I wrote a
servlet to do file upload using the commons jar. This part is working fine and I'm able to upload files successfully to the server.
My question is How do I determine the file type of each file? Users can upload files with any extensions as long as the content is text.
Eg,
The user can upload test1.txt, test2.abc, test3.fa, if all 3 files are text-based.
On the other hand, I want to stop the upload if the file is an image file, even if the filename is image.txt.
So, is there a way to check and validate the content of the file and determining the file type without restricting the file extensions?