简体   繁体   English

File API在Firefox中为pdf文件返回“无效/八位字节流”

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

I'm doing file upload which checks file mime type in browser. 我正在执行文件上传,该文件检查浏览器中的文件mime类型。 It's uses jQuery File Upload Plugin and works good everywhere except one user. 它使用jQuery File Upload Plugin,除一个用户外,其他任何地方都可以正常工作。

For some reason file.type (html5 file api) returns " invalid/octet-stream " for pdf file (usually it's "application/pdf"). 由于某种原因,pdf文件的file.type(html5文件api)返回“ invalid / octet-stream ”(通常是“ application / pdf”)。 Pdf file is simple and can be opened at this pc without any problems. PDF文件很简单,可以在此PC上打开而没有任何问题。

Environment: Windows 7 and Firefox 40. Not reproduced in chrome or explorer. 环境:Windows 7和Firefox40。不在chrome或Explorer中复制。

Try deleting (or renaming/moving, for testing purposes) the file MimeTypes.rdf in the affected Firefox's profile folder . 尝试删除(或重命名/移动,以进行测试)受影响的Firefox的配置文件文件夹中的MimeTypes.rdf 文件

(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".) (在Windows下,通常可以在类似于c:\\ Users \\ [name] \\ AppData \\ Roaming \\ Mozilla \\ Firefox \\ Profiles \\ [some id] .default的路径下找到-或仅搜索“ 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). 如果PDF上传之后可以正常工作,则您遇到了Firefox错误 ,该错误于2007年首次报告( 此处基本相同 ,于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. 简而言之,就下载的文件的扩展名而言,用户曾经从中下载文件的任何网站都有可能破坏MimeTypes.rdf文件,这是恶意的,无意的/无意的。

Things you can do: 您可以做的事情:

  1. Vote for the Firefox bug! 为Firefox错误投票!
  2. Quick fix to get it working for the one user right now: Have the user delete their MimeTypes.rdf file. 快速修复,使其立即可用于一个用户:让用户删除其MimeTypes.rdf文件。 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. Firefox将在下一次启动时创建一个新的“新鲜”文件,但这将清除用户随着时间的推移创建的所有MIME类型/应用程序关联。 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. 同样,这仅在用户从其他网站上下载了下一个PDF文件,而该文件再次破坏MimeTypes.rdf文件时才有用。
  3. Use the "user agent" header to determine if the file is uploaded from Firefox. 使用“用户代理”标题确定文件是否从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). 如果是这样,并且MIME类型与您希望接受的任何内容都不匹配,请仔细检查文件名的扩展名,如果该扩展名与您接受的文件类型(在您的情况下为“ .pdf”)匹配,则无论如何都要接受该文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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