[英]How to validate a uploaded file in java
I need to allow the user to upload only text files(.txt,.doc,.rtf etc). 我需要允许用户仅上传文本文件(.txt,.doc,.rtf等)。 How can i validate the uploaded files contains only text data.
如何验证上传的文件仅包含文本数据。 I need to validate the data in the file not the file extension.
我需要验证文件中的数据而不是文件扩展名。
If the user uploads any Image or video files etc other than text files I need to display like "The format of the file you uploaded doesn't match the format required" 如果用户上传了除文本文件以外的任何图像或视频文件等,我需要显示为“您上传的文件格式与所需格式不匹配”
You can try to use Apache Tika library . 您可以尝试使用Apache Tika库 。 It can find out type of a file by its content.
它可以通过其内容找出文件的类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.