Firefox 和 Content-Disposition 标头
我对附件名称有疑问。当我在谷歌浏览器上调用该网站时,它会返回具有正确名称和扩展名的文件。我用 Internet Explorer 测试了一下,效果也很好。该问题仅存在于 Firefox 中。我致电该网站,它返回文件标题的第一个单词,但没有扩展名。
例如,如果我想要一个名为“My report.docx”的文件,它会变成一个名为“My”的文件。我用谷歌搜索了一下,结果发现这是人们的一个常见问题,因为浏览器读取标题的方式不同。他们说修复方法是引用文件名:
Content-Disposition:附件; filename=My Report.docx
现在是:(注意引号)
Content-Disposition:附件; filename="My Report.docx"
但是,这对我不起作用。
在 Chrome 上,它返回“My Report.docx”(实际上带有引号)。 Firefox 返回了一个奇怪的文件,该文件具有正确的扩展名和正确的名称,但没有引号,但无法执行。它是正确的文件大小、正确的扩展名和正确的名称,但无法执行。它还在文件名前后返回一个空格。
I have a problem with an attachment's name. When I call the site on google chrome it returns the file with the right name and extension. I tested it with internet explorer and it works fine too. The issue lies with only Firefox. I call the site and it returns the first word on the file title and no extension.
For example if I wanted a file called "My report.docx" it turns a file called "My". I Googled around and it turns out this is a common issue with people because browsers read the headers differently. They said the fix is to quote the file name:
Content-Disposition: attachment; filename=My Report.docx
is now: (note the quotes)
Content-Disposition: attachment; filename="My Report.docx"
However, that did not work for me.
On chrome it returned "My Report.docx" (actually with the quotes). Firefox returned a odd file that had the proper extension and proper name and no quotes yet it could not be executed. It was the proper file size, proper extension, and proper name yet it could not be executed. Also it returns a space before and after the file name.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我知道这是一个很老的问题,但我最近遇到了同样的问题。解决方案是按照
由于您已经尝试过 2,因此您可以尝试使用 1 并看看效果如何。
通常我使用
ContentDisposition
类为我生成标头:希望这会有所帮助。
I know this is a very old question, but I was recently having the same problem. The solution is to either
Since you've already tried 2, you could try using 1 and seeing how that works out.
Usually I use the
ContentDisposition
class to generate my header for me:Hope this helps.
这应该按预期工作,这是另一个具有相同问题的 SOq:
以及 Mozilla 页面(我猜您正在引用这个):
我不知道您的服务器端代码的具体情况,但这里有一些需要确认/尝试的事情:
wget
或curl
来执行此操作。Content-Type
标头?.png
或.xls
吗?事实上,最简单的方法可能是尝试纯文本文件 (text/plain
),然后从那里获取它。希望这有帮助。
This should work as expected, here's another SOq with the same problem:
and also the Mozilla page (I guess you were referencing this one):
I don't know the specifics of your server side code, but here are some things to confirm / try:
wget
orcurl
from the command line or something like that.Content-Type
header correctly?.png
or a.xls
? In fact, probably the easiest would be to try a plain text file (text/plain
) and then take it from there.Hope this helps.