indiWiz.com

Subhash's Tech Log

Forcing HTTP Download

with one comment

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:

  1. inline: This will render the content inline in the browser.
  2. 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.

Written by Subhash Chandran

March 11th, 2009 at 11:36 am

Posted in Software Dev

Tagged with

One Response to 'Forcing HTTP Download'

Subscribe to comments with RSS or TrackBack to 'Forcing HTTP Download'.

  1. 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

Leave a Reply