views:

210

answers:

1

My Rails site allows users to upload documents, I am using the attachment_fu plugin. I have a list of allowed [MIME] content types that I allow - the standard image formats, Office documents, PDF, etc. I have a user who cannot upload any PDF documents because the validation fails, looking in the logs attachment_fu thinks the MIME type is "application/x2x-download". The users browser is Firefox on Windows XP. When I try to upload the PDF myself using Firefox on OS X or Safari or IE 6/7/8 it works just fine. Seems to just be an issue with her browser.

I googled around for this MIME type and it seemingly doesnt exist.

In theory, I could ignore the MIME type that the client is telling and attempt to identify the file myself, maybe shell out to the file -b --mime-type command, but this just seems janky.

The other popular Rails attachment plugin, Paperclip, does not do the MIME identification itself and also attempts to trust the client browser.

What do you y'all think? Ignore the client and [attempt to] identify the upload myself or try to figure out why this users browser is setting a totally invalid MIME type in the first place?

+1  A: 

Many 3rd party applications can modify the client mime type settings (I had my own adventure with Amazon's MP3 downloader app modifying mime types), so it is quite likely that your user has something similar (maybe something from x2x software).

I'd recommend sticking with mime/type as a means of communicating what is and isn't valid back to your users, with a secondary check using ruby filemagic in a validation.

Mike Buckbee