views:

338

answers:

3

Hi, all.

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.

A: 

This doesn't answer your question, but solves, I hope, original problem.

I would just add timestamp (something unique enough) to query string of link to CSV file. It helped for me.

Grzegorz Gierlik
+1  A: 

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.

kosoant
No, I just use plain HTTP.
Satoru.Logic
+3  A: 
scunliffe
Thx for your explanation. But I think this may not be the same problem I encountered. I explicitly set 'Content-Disposition' to 'attachment' and I think this will, hopefully, prevent the file from being opened even in IE.
Satoru.Logic