On Fri, 16 Jul 2010 10:26:11 -0400, Christopher Schultz <ch...@christopherschultz.net> wrote:


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.


Thanks for all the suggestions & ideas. We are leaning towards using a simple filename/extension check, as we feel that will catch 99%+ of the problems. One additional option we'll look at is:

java.net.URLConnection.guessContentTypeFromName(fileName)

In case anyone's interested, Firefox seems to maintain a cache of mime type mappings in the user profile (mimeTypes.rdf). This can (for reasons unclear) get messed up, and can result in Firefox reporting the wrong mime type on a file upload. We had one instance of a user uploading a PDF and Firefox was reporting it as video/x-flv. Deleting the mimeTypes.rdf file causes FF to create an fresh default copy and removes the problem.

Thanks again-
Steve


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

Reply via email to