• Post Reply Bookmark Topic Watch Topic
  • New Topic

Define mime type for file upload

 
Anks Gupta
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am using <t:inputFileUpload> for file uplaod feature. I want to restrict the files shown to only pdf files when i click on browse button, i.e. i want to fix the mime type or accept to pdf when the dialogue box appears on click of browse button.

I tried putting accept="application/pdf" in accept tag of t:inputFileUpload but it didnt worked.

Can it be handled in web.xml or is there any other approach to handle this.

Need your help as this is a bit urgent.

Thanks in advance
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anks Gupta wrote:I am using <t:inputFileUpload> for file uplaod feature. I want to restrict the files shown to only pdf files when i click on browse button, i.e. i want to fix the mime type or accept to pdf when the dialogue box appears on click of browse button.

I tried putting accept="application/pdf" in accept tag of t:inputFileUpload but it didnt worked.

The accept attribute is ignored by most web browsers. They are not required to implement it.
Read the HTML forms specification: http://www.w3.org/TR/html401/interact/forms.html#adef-accept
There is stated "may", not "must".

Opera usually very strictly follows the w3 specs, so it is as far the only browser which actually supports it.

Can it be handled in web.xml or is there any other approach to handle this.

Need your help as this is a bit urgent.

Thanks in advance

You can determine the content type programmatically based on the file extension using ServletContext#getMimeType() or maybe even based on the actual file contents using URLConnection#guessContentTypeFromStream().
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!