I have a file uploader module. The UI is created using simple HTML and Javascript. Server side I am using Java code. I want to check the type of the uploaded file.
Asked
Active
Viewed 1,618 times
0
-
see also http://stackoverflow.com/questions/51438/getting-a-files-mime-type-in-java – Mark Elliot Jun 21 '10 at 04:09
-
In server side or client side?? – rahul Jun 21 '10 at 04:10
-
@Rahul:I want to check the file type in Server side. – Puru Jun 21 '10 at 04:13
1 Answers
0
Files don't really have types. The best you can do would be to attempt to load the file as an XLS.
- If the load succeeds, the file is most likely an XLS.
- If the load fails, the file is either an invalid/malformed XLS, or not an XLS at all.
You can also look at the uploaded file name or the content type, but neither of these is definitive; i.e. they might say that the file is an XLS when it is something completely different.

Stephen C
- 698,415
- 94
- 811
- 1,216