Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"download link " fails in IE

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)

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

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

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

del response.headers['Cache-Control']

It works in IE.

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

Now, my question is:

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

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

Thanks in advance.

like image 894
satoru Avatar asked Jan 04 '10 14:01

satoru


2 Answers

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

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.

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

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"');
like image 181
scunliffe Avatar answered Oct 03 '22 10:10

scunliffe


Is the download link using https (ssl)? If so, then IE can't handle the downloading if it's set to be cached. This is a known problem with IE.

like image 35
kosoant Avatar answered Oct 03 '22 09:10

kosoant