This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

File upload filter for displaying files

 
Steve Renard
Ranch Hand
Posts: 66
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic