Hugo Palma Hugo Palma - 26 days ago 6
HTTP Question

How to set response filename without forcing saveas dialog

I am returning a stream in some response setting the appropriate content-type header. The behavior i'm looking for is this:


  • If the browser is able to render content of the given content-type then it should display it in the browser window.

  • If the browser doesn't know how to render the content then it should display the saveas dialog where the filename should be one provided in the response.



The problem that if i set the Content-Disposition header with:


"attachment; filename="myfile.txt""


the browser will always display the savesas dialog.

If i don't set the Content-Disposition the filename used in the saveas dialog is the one in the url that doesn't work in my case.

I also tried setting the Content-Disposition to inline but the outcome is the same.

Answer

The correct way could be:

Content-Disposition: inline; filename="myfile.txt"

Comments