简体   繁体   中英

File API returns “invalid/octet-stream” for pdf file in Firefox

I'm doing file upload which checks file mime type in browser. It's uses jQuery File Upload Plugin and works good everywhere except one user.

For some reason file.type (html5 file api) returns " invalid/octet-stream " for pdf file (usually it's "application/pdf"). Pdf file is simple and can be opened at this pc without any problems.

Environment: Windows 7 and Firefox 40. Not reproduced in chrome or explorer.

Try deleting (or renaming/moving, for testing purposes) the file MimeTypes.rdf in the affected Firefox's profile folder .

(Under Windows this can usually be found under a path similar to c:\\Users\\[name]\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\[some id].default - or just search for "MimeTypes.rdf".)

If the PDF upload works afterwards, you encountered a Firefox bug that was first reported in 2007 ( basically the same here , reported in 2006). In a nutshell, any web site from which the user ever downloads a file has the potential to corrupt the MimeTypes.rdf file in regards to the extension of the downloaded file - maliciously or accidentally/unknowingly.

Things you can do:

  1. Vote for the Firefox bug!
  2. Quick fix to get it working for the one user right now: Have the user delete their MimeTypes.rdf file. Firefox will create a new, "fresh" one at the next start, but this will clear all MIME type / application associations that the user has created over time. Also, this will only help until the user downloads the next PDF file from some other web site that corrupts the MimeTypes.rdf file again.
  3. Use the "user agent" header to determine if the file is uploaded from Firefox. If so and the MIME type doesn't match anything you wish to accept, double-check the file name's extension and accept the file anyway if the extension matches your accepted file type(s) (".pdf" in your case).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM