Forcing HTTP Download
To force HTTP download of a dynamically generated content, I usually set the HTTP header Content-Type to application/octet-stream. This forces the browser to display the Save dialog box. But this has the limitation of sending the wrong content-type even when we know the correct one. Recently I discovered another HTTP header which solves this problem. This is the Content-Disposition header. This can take following two vales:
- inline: This will render the content inline in the browser.
- attachment: This will force the browser to display the Save dialog.
When generating dynamic content, it is also recommended to specify proper filename. This file name can also be specified as a parameter to Content-Disposition header. An example:
Content-Disposition: attachment;filename=document.pdf
Content-Disposition is covered in RFC 2183.
Found that if I use inline then I should NOT use
filename=document.pdf, this will NOT work in IE.
(other browsers ignore it)
Fred
18 Sep 09 at 6:34 pm