10

I'm forcing a download to be handled by the browser by setting the header Content-disposition to inline;

Is there a way of setting the title this way? Currently it looks like the browser auto-fills it with the URL of the file.

AlbertEngelB
  • 16,016
  • 15
  • 66
  • 93

2 Answers2

6

It is possible, just make the end of your URL to contain the filename, be sure to URLEncode it, most browsers will ignore the queryString

localhost:3000/blah/blah/blah/Attachment%3A%20Screen%20Shot.png/?id=1670674338147205293

Tab Display = "Attachment: Screen Shot.png"

Works fine on Chrome, Firefox, and Opera . . . Safari displays either the domain or the entire URL depending on your settings

Travis May
  • 71
  • 1
  • 3
2

Yes, you can specify the filename just like you'd do for content-disposition: attachment, i.e. like this:

Content-disposition: inline; filename="foo.bar"

See this post for some useful information about this header: How to encode the filename parameter of Content-Disposition header in HTTP?

Community
  • 1
  • 1
ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
  • 8
    This doesn't seem to work when setting it to `inline;` After loading the file via POST, here's my `Content-disposition` header: `Content-disposition:inline; filename="foo.bar"` The title of the page is still gets set to `localhost:3000/blah/blah/blah` If I try and save the file, the filename is set, but I'm hoping to set the tab's title. – AlbertEngelB Feb 14 '14 at 21:37
  • 3
    Ah, that's impossible. A file has no title in the browser. – ThiefMaster Feb 14 '14 at 22:48