I'm using JSF/Tomahawk library for my application.
For a file upload functionality, I have used t:inputFileUpload tag.
It works fine and am able to upload & download back the file.
But, how do I filter files in the file selection dialog to display only *.doc files?
Any help is appreciated.
The HTML input type="file" element has an 'accept' attribute which is specified by the W3 HTML specification as optional. You can define in there the content types (mime types) which are to be displayed in the browse dialog only. Unfortunately a lot of webbrowsers doesn't support it. As far now only Opera, which very strictly follows the W3 HTML spec, supports it.
To fullfill this requirement, you need to validate it at the server side at any way. You can use ServletContext#getMimeType() for it to validate the file extension against the mime mapping configuration of the appserver in question. Alternatively you can use URLConnection#guessContentTypeFromName() to validate the file extension against the file type configuration of the underlying operating system.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com