1

I get the content type from the header, I need to get the extension of this content type.

eg: content type is application/java-archive then I want a string output as jar.

Andremoniy
  • 31,241
  • 14
  • 110
  • 218
Mizan
  • 410
  • 1
  • 5
  • 26
  • It would be better to generate the file extension where the the content type is generated. Otherwise you can construct a map content-type -> extension of your preference. As mentioned, there is not exact mapping between mime types and file extensions. – khachik Jan 11 '13 at 12:01
  • What is the purpose of this? If you can add more context that would be helpful for answerers. Thanks. – Jonathan Jan 11 '13 at 12:01
  • I need to restrict some types of file as a attachment – Mizan Jan 11 '13 at 12:02
  • @Mizan limit the files to the content type not to any extension. – Uwe Plonus Jan 11 '13 at 12:05
  • 1
    Related: http://stackoverflow.com/questions/4169713/how-to-check-a-uploaded-file-whether-it-is-a-image-or-other-file/4169776#4169776 – BalusC Jan 11 '13 at 14:26
  • There is no mapping from content type to file extension. E.g. the content type `image/jpeg` may be mapped to either `.jpg` or `.jpeg`. Also how do you want to map `application/octet-stream` which is used for any binary file? – Uwe Plonus Jan 11 '13 at 11:57
  • Ok , got your point . Is there a way to get the extension directly from the header ? – Mizan Jan 11 '13 at 12:03
  • @Mizan At the moment I don't know but there could be a header with the file name. – Uwe Plonus Jan 11 '13 at 12:05
  • I can get the file name from the params :) so i will check the file name now .However checking the content type is much better i believe. if i check conten type then the user cant upload a .bat file just by changing the file extension. – Mizan Jan 11 '13 at 12:19

0 Answers0