Search code examples
firefoxheadercontent-disposition

Firefox and Content-Disposition header


I have a problem with an attachment's name. When I call the site on google chrome it returns the file with the right name and extension. I tested it with internet explorer and it works fine too. The issue lies with only Firefox. I call the site and it returns the first word on the file title and no extension.

For example if I wanted a file called "My report.docx" it turns a file called "My". I Googled around and it turns out this is a common issue with people because browsers read the headers differently. They said the fix is to quote the file name:

Content-Disposition: attachment; filename=My Report.docx

is now: (note the quotes)

Content-Disposition: attachment; filename="My Report.docx"

However, that did not work for me.

On chrome it returned "My Report.docx" (actually with the quotes). Firefox returned a odd file that had the proper extension and proper name and no quotes yet it could not be executed. It was the proper file size, proper extension, and proper name yet it could not be executed. Also it returns a space before and after the file name.


Solution

  • This should work as expected, here's another SOq with the same problem:

    and also the Mozilla page (I guess you were referencing this one):

    I don't know the specifics of your server side code, but here are some things to confirm / try:

    • If you have PHP available at the server, can you try the code from the first link above? If not, you can probably find something on the Net in your language of choice. That way, you can confirm whether the issue is in your code or somewhere else (server setup, browser, etc.)
    • Is this happening on other client machines (i.e. where you try the download from) or only on that one? You might want to try others to confirm.
    • Is this working fine in IE / Safari or some other browser? You can even try doing it with wget or curl from the command line or something like that.
    • Are you also providing the Content-Type header correctly?
    • Can you try downloading some other file or a file of a different type, e.g. a .png or a .xls? In fact, probably the easiest would be to try a plain text file (text/plain) and then take it from there.

    Hope this helps.