"下载链接"在IE中失败 [英] "download link " fails in IE

查看:98
本文介绍了"下载链接"在IE中失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图实现一个下载链接",并将其放在报表表的旁边,以便用户可以下载csv文件并使用Excel之类的应用程序将其打开.

I was trying to implement a "download link" and put it beside one of my report table so that users can download a csv file and open it with applications like Excel.

记录是根据用户的查询动态生成的.

The records are generated dynamically based on the query made by users.

因此,在控制器中的某处类似:

So somewhere in my controller there's something like:

response.headers['Content-Type'] = 'text/csv'
response.headers['Content-Disposition'] = 'attachment; filename=xxx.csv'
return response.stream(dynamically_generated_csv, request=request)

这在FireFox& Chrome,但在IE中失败.

This works in both FireFox & Chrome, but fails in IE.

当我打印出响应标头时,我发现web2py已将多个标头添加到我的响应中:'Expires','Cache-Control'等...

When I print out the response headers, I found that several headers were added to my response by web2py:'Expires', 'Cache-Control', etc...

当我通过执行以下操作删除"Cache-Control"标头时:

And when I remove the 'Cache-Control' header by doing the following:

del response.headers['Cache-Control']

它在IE中有效.

因此,似乎IE在处理"Cache-Control"设置为特定值的可下载文件时遇到问题.

So it seems like IE has trouble dealing with a downloadable file with 'Cache-Control' set to certain value.

现在,我的问题是:

  • 为什么web2py隐式添加这些响应标头?也许没有办法将其关闭?

  • Why does web2py add these response headers, implicitly? and maybe without a way to set it off?

当我以这种方式删除"Cache-Control"标头时有副作用吗?

is there any side effect when i delete the 'Cache-Control' header this way?

谢谢.

推荐答案

我不确定正在/正在发送哪些缓存控制标头,但IE会像您遇到的那样下载文件时出现错误.

I'm not sure what Cache control headers are/were being sent but IE has a bug with downloaded files like you are experiencing.

对于IE,您必须启用缓存.当IE加载文件(例如Excel文件)时,在Excel中,它是从缓存目录中加载文件的,因此,如果不缓存它,则Excel(或其他应用程序)将无法加载文件.

For IE, you MUST enable caching. When IE loads files (e.g. Excel files), in Excel, it loads them from the cache directory, thus if you don't cache it, Excel (or your other app) will fail to load the file.

有关该主题的埃里克法律(MSFT):

Eric Law (MSFT) on the topic: http://blogs.msdn.com/ieinternals/archive/2009/10/02/Internet-Explorer-cannot-download-over-HTTPS-when-no-cache.aspx

更新 :但是,如果您只是想强制下载...,例如没有让IE在IE窗口内加载excel文件...然后确保设置附件的完整标题.

Update: If however you just want to force the download... e.g. not have IE load the excel file inside the IE window... then be sure to set the full headers for the attachment.

//PHP style
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename="downloaded.pdf"');

这篇关于"下载链接"在IE中失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆