I recently incorporated mime-util (http://sourceforge.net/projects/mime-util/) into a project of mine that needed reliable mime detection. It works pretty well and is easily extensible especially for text types.
Robert On Nov 12, 2010, at 11/127:56 AM , [email protected] wrote: > Hi guys, > > When using tapestry-upload I stumbled across an unusual browser bug that I > spent hours on, so wanted to share... maybe it helps someone else: > > Unlike weaker implementations, UploadedFile.getContentType(); returns the > mime type of the uploaded file by extracting it from the http header > 'Content-Type' after the file posts. To my knowledge this is the best > approach... examining the file extension has obvious drawbacks. Unfortunately > I found Firefox 3.6.12 sets the header incorrectly on Windows, but correctly > on Linux... I am willing to bet some more inconsistent browser > implementations exist as well, so be warned that while Tapestry does its > part, your code may not work as expected or may contain subtle bugs because > browsers can't be trusted to set this header correctly. > > I am not sure if some of the tapestry gurus can come up with a better > solution, but I work around this problem by combining checks, falling back on > a file extension check when I detect a problem... If anyone has a better > suggestion I would love to hear it. > > Cheers, > Peter > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
