File upload gotcha: PDFs get different mime types per browser
I've had some time over the last few days to start adding some of the "nice to have" features to a client site before delivering it, and one of those was the ability to upload product images and related PDFs, rather than having to teach them to always follow the naming scheme and how to use FTP. While testing my uploads in various browsers, I came across something I found to be very odd.
When you upload a PDF in IE, the file you receive has what I believe is the correct mime type: "application/pdf" however when you upload the same PDF file using the same code, in Firefox (tested in FF 2 and 3), the mime type is "application/download". I can't explain it. I have no idea why it's wrong. But it is, and consistently so. Could this be the one thing that is implemented correctly in IE and incorrectly in Firefox?
At any rate, it's a simple thing to accommodate. Note the accept attribute of the <CFFile> tag in the code sample below:
Posted in ColdFusion | 19 Responses
Just a thought :)
@Todd: That doesn't actually check the mime type of the file, just the last few characters of the file name. Not that it's a big risk in this implementation (back-end data administration), but I suppose if I can work this method out I would prefer it. If all else fails, I'll definitely fall back on that.
Thanks again IE team, you really keep life interesting!
i'm pretty sure i tested on both firefox 2 and 3. i only just upgraded firefox the other day, so it was probably ff2. will have to test ff3 tonite and verify (this is a project on my home machine). to be honest... not sure i even tested on IE (yet).
out of curiosity... how did you test the mime type to ascertain that FF is seeing it as 'application/download'?
What version of Firefox are you using? I wish I could make a test page from my dev server public for you, but it's internal only and I don't think I can get a VPN request approved for this. ;)
So my whole point is, just sniff the extension yourself... if neq 'pdf' then delete it and move on...
- application/java-vm
- application/x-java-serialized-object
- text/html
- application/xml
- image/gif
- image/x-bitmap
- image/x-pixmap
- image/png
- image/jpeg
- image/jpg
- image/vnd.fpx
- audio/basic
- audio/x-wav
I stand corrected...I suck...
In your test, was IE and FF on the same computer?
Could it be that your FF just did not know what a PDF is?
Is there any PDF reading application installed on the same machine?
Or maybe some FF plug-in is at fault here? Or at any prior time did you ever select to download a pdf file and checked the 'always do this for this type of files' on a FF open/save file dialogue box?
Not sure if any of the above actually can cause the issue - just looking for possible explanations. But it sure seems like an individual computer setup issue to me...
Something I can try is a blank FF profile.
All works fine in IE.
FF uses a file called mimeTypes.rdf, where it stores info about what applications to use to open a file of a particular mime type and what mime type to send the file as when uploading it. this is a per-profile file. what FF stores in it depends on what you select to do with the file when downloading it. some FF add-ons can change that file as well.
the result is that a file you know to be a certain mime type will be uploaded by FF with a totally different mime type. i.e. my pdfs are now uploaded by FF as binary/octet-stream...
Azadi