-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Manos,

On 7/16/2010 9:42 AM, Manos Batsis wrote:
> On 07/16/2010 04:21 PM, Stephen Turner wrote:
>> We're using Struts 2 for file uploading, and we're filtering the types
>> of files people can upload by checking the file's content type against a
>> list of allowed mime types.
>>
>> This turns out not to be reliable enough. Firefox in particular seems to
>> sometimes provide the wrong mime type, so some valid files are being
>> rejected.
>>
>> My question is: has anyone come across a reliable way to detect a file's
>> mime type?
> 
> When dealing with a finite set of MIME types, we usually map those to
> file extensions. We then only allow those extensions to be used in
> uploaded files.

If filename extensions are sufficient, you can get this information
directly from the servlet container using ServletContext.getMimeType.
There's also the activation framework's MimetypesFileMap.getContentType.

Another option might be to use the UNIX 'file' command, which will
actually scan part(s) of the content of the file to determine what it
is. It does not emit MIME types, though.

Here's some good information, too:
http://fredeaker.blogspot.com/2006/12/file-type-mime-detection.html

Good luck, and let us know what you find.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkxAbAMACgkQ9CaO5/Lv0PD08ACfeSV1PZ1QJK6rpZI2K4+bo5s6
/xkAoI8+WVcycpOQ2AltMs42RskumbJO
=se6p
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to