Downloading files in Internet Explorer over SSL

There’s a known problem with Internet Explorer when it tries to download files on a secure site (i.e. one with a https prefix). For some reason, IE tries to save the file as an attachment, instead of displaying it in the browser (e.g. an image or PDF). You can fix this issue by altering some of your browser settings, which is fine for an individual user but obviously doesn’t work if you run a website and want users with Internet Explorer to be able to download files from it. The issue appears to affect even the latest version of IE, so you cannot just ignore it in the hope that everyone has upgraded from IE 6 now.

I encountered this issue on a project I was working on, and after many attempts using trial and error I found that you need to send the following headers before the file is downloaded:

Cache-control: private
Content-Type: application/pdf
Pragma: public

I don’t think the order matters, but the sequence above works for me and I haven’t tried moving the headers around. Of course, you should replace application/pdf with the content type for whatever file you are sending to the browser.

This fix does not affect other browsers, which all seem to download the file perfectly well without the headers, nor does it break downloads on non-SSL sites. I don’t know why it works, but I’m posting it online in the hope that other people who are encountering the same problem won’t have to waste half a day trying to fix it.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.