简体   繁体   中英

How to validate a uploaded file in java

I need to allow the user to upload only text files(.txt,.doc,.rtf etc). 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 . It can find out type of a file by its content.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM