带有内容处置的文件:内联有时仍然提示下载

发布于 2024-07-18 06:49:20 字数 646 浏览 8 评论 0原文

我的主题行说了我要问的大部分内容。 我有一个网站,可以输出各种格式的报告(HTML、CSV、TSV、Excel 等)。 只要有可能,我希望这些文件显示在浏览器中。 为此,我设置了标题,以便“Content-Disposition”为“内联”。 这对于不同的文件类型来说非常不一致。 似乎在 FF3 和 IE7 中,HTML 总是会自动内联打开。 这就说得通了。 如果我使用 TSV,两个浏览器都会提示下载,因为它在我的系统上是未知的文件类型。 这也是有道理的,也正是我想要的。 然而,Excel 和 CSV 提供不同的行为。 在FF中,两者总是提示下载或打开。 如果我选择“打开”,它将在新窗口中打开。 在 IE 中,提示下载或打开 - 我无法弄清楚这一点。 我认为 Excel 文件会通过 Content-Disposition: inline 自动内联打开。 如果我在 IE 中选择“打开”,它将在浏览器中内联打开。

有人可以解释意外的行为吗? 这对我来说并不是真正的问题,但我的用户认为这是一个错误,因此我可以向他们引用的权威来源将是非常好的。 到目前为止,我发现的关于这个“问题”的唯一内容是 Mozilla 论坛上的一篇 1 行帖子,内容是关于自动打开内联功能如何成为 IE 的安全缺陷之一......那是一篇旧帖子,所以也许它IE7 中“修复”了吗? 谢谢。

My subject line says most of what I'm asking. I've got a web site that outputs reports in various formats (HTML, CSV, TSV, Excel, etc). Whenever possible, I'd like these files to be shown in the browser. To that end, I've set up my headers so that "Content-Disposition" is "inline". This works very inconsistently with different file types. It seems that in both FF3 and IE7, HTML will always open inline automatically. That makes sense. If I use TSV, both browsers will prompt for download, since it's an unknown file type on my system. That also makes sense and is exactly what I want. Excel and CSV, however, offer different behaviors. In FF, both always prompt for download or opening. If I choose "open", it opens in a new window. In IE, both also prompt for download or opening -- I can't figure this one out. I thought Excel files opened inline automatically with Content-Disposition: inline. If I choose "open" in IE, it opens inline in the browser.

Can someone explain the unexpected behavior? This isn't really a problem for me, but my users think it's a bug, so an authoritative source I can cite to them would be excellent. The only thing I've found so far about this "issue" is a 1 line post on a mozilla forum about how the auto-open-inline thing is one of IE's security flaws... that was an old post, so maybe it was "fixed" in IE7? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

唯憾梦倾城 2024-07-25 06:49:20

您可能已经解决了这个问题,但如果没有,我可能有一个答案(对于将来遇到同样问题的人,这也让我发疯!)

可以使用以下命令在客户端上覆盖此行为:

  1. 转到 Windows 资源管理器
  2. 选择工具-> 文件夹选项
  3. 选择“文件类型”选项卡
  4. 查找扩展名“DOC”(或“PDF”等)
  5. 选择“高级”
  6. 根据需要勾选/取消勾选“下载后确认打开”。

用于实现预览/下载功能的机制是通过使用“content-disposition”标头,通常使用 MimeType“application/”。 这基本上告诉本地客户端使用指定的应用程序打开应用程序,但是应用程序的上述设置可能会覆盖请求的传递格式。

You may have resolved this already, but if not I may have an answer (for future people with the same issue, this also drove me nuts!)

This behavior can be overwritten on the client, using the following:

  1. Go to windows explorer
  2. Select Tools -> Folder Options
  3. Select “File Types” Tab
  4. Find extension “DOC” (or “PDF”, etc)
  5. Select “Advanced”
  6. Tick / Untick “Confirm open after download” as desired.

The mechanism used to implement the preview / download functionality is via the use of the “content-disposition” header, usually using MimeType “application/”. This basically tells the local client to open the application using the specified application, however the above settings for the application can overwrite the requested delivery format.

垂暮老矣 2024-07-25 06:49:20

检查您的服务器是否为 CSV 和 Excel 文件提供正确的 MIME 类型。 为了正确处理它们,即使浏览器能够识别它们的类型并具有文件类型处理程序/插件,也需要正确的 MIME 类型。

您可能希望两者的 MIME 类型均为 application/vnd.ms-excel

如果您将这些文件作为常规文件通过 Web 服务器提供,则 Apache 中的相关设置是 mime.types 文件。

application/vnd.ms-excel xls csv

如果您从应用程序提供这些文件,则需要自行添加 Content-Type: application/vnd.ms-excel 标头。

请注意,对于某些用户来说,您可能永远无法使其按预期工作 - 例如,未安装 Microsoft Office 的任何人,甚至使用替代浏览器的任何人或弄乱了文件类型关联的人。

(出于您的兴趣,这篇文章 描述了该过程 - 它恰好能够 Plone/Zope 但想法是相同的)。

Check that your server is serving the correct MIME type for the CSV and Excel files. In order to treat them properly, even a browser which recognises their type and has a file type handler/plugin for them will need the correct MIME type.

You will probably want the MIME type of both to be application/vnd.ms-excel

If you are serving these with your web server as regular files, then the relevant setting in Apache is the mime.types file.

application/vnd.ms-excel xls csv

If you are serving these files from your application, then you'll need to add the Content-Type: application/vnd.ms-excel header yourself.

Note that for some users, you may never get it to work as expected - for example anyone who doesn't have Microsoft Office installed, or even anyone using an alternative browser or who has messed with their file type associations.

(for your interest, this article describes the procedure - it happens to be able Plone/Zope but the idea is the same).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文