mime-util works by a series of detectors. You can register any or all of the default detector types, or add your own. It comes with a "MagicMimeMimeDetector" (uses a unix "magic" file; comes bundled with its own for non-*nix systems), an "OpenDesktopMimeDetector" (again, comes bundled with it's own mime.cache), and a file extension detector. It will ask all registered detectors to id the file, and then weights/ranks the mime type according to how many detectors gave the same file type. So far, it's working well for me. Sucks that Firefox is unreliable in this aspect.
Robert On Nov 15, 2010, at 11/152:59 AM , [email protected] wrote: > Hi Robert, > >> 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. > Thanks! I will take a look at mime-util to understand exactly how it works, > if it tries to extract the mime type from the actual data then it might do > the trick. > > FYI, I filed a bug report with Mozilla, but this bug has apparently existed > since 2007 in one form or another, and is blocking several others... > apparently Firefox looks at the clients configuration (plugins and Windows > registry) to determine valid mime types instead of providing its own map, and > obviously this is flawed since client configuration isn't constant or > guaranteed to even be present or correct for that matter. Thus, Firefox (not > IE for once) renders the Content-Type browser header unreliable for > developers to use... tapestry-upload should consider using an alternative. > > Cheers, > Peter > > > ----- Original Message ----- > From: "Robert Zeigler" <[email protected]> > To: "Tapestry users" <[email protected]> > Sent: Sunday, 14 November, 2010 01:48:36 GMT +02:00 Athens, Beirut, > Bucharest, Istanbul > Subject: Re: tapestry-upload firefox bug > > 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] > > > --------------------------------------------------------------------- > 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]
