1

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"

  • 1
    A possible duplicate of http://stackoverflow.com/questions/8659698/txt-file-format-validation-in-java – AurA Nov 02 '12 at 10:44
  • 1
    Check this out http://stackoverflow.com/questions/3576129/best-way-to-determine-mime-type-of-a-file-in-java – Ankit Nov 02 '12 at 10:54

1 Answers1

1

You can try to use Apache Tika library. It can find out type of a file by its content.

Ivan Mushketyk
  • 8,107
  • 7
  • 50
  • 67