Firefox Header and Content-Disposition

I have a problem with the name of the attachment. When I call the site on google chrome, it returns a file with the correct name and extension. I tested it with Internet Explorer and it works great. The problem is only in Firefox. I call the site and it returns the first word in the file header and without extension.

For example, if I need a file called "My Report .docx", it turns a file called "My". I googled around, and it turns out this is a common problem with people, because browsers read headers in different ways. They said that the fix should indicate the file name:

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

now: (note the quotation marks)

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

However, this did not work for me.

On chrome, he returned "My report .docx" (actually with quotation marks). Firefox returned an odd file that had the correct extension and proper name, and so far no quotes have been executed. It was the correct file size, the correct extension, and its own name, but it could not be executed. It also returns a space before and after the file name.

+8
firefox header content-disposition
source share
2 answers

This should work as expected, here is another SOq with the same problem:

  • Uploading a file with a different name to the saved name

as well as the Mozilla page (I suppose you linked to this):

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

  • If you have PHP available on the server, can you try the code from the first link above? If not, you can probably find something on the web in your language of choice. This way you can check if there is a problem in your code or somewhere else (server setup, browser, etc.).
  • Does this happen on other client computers (i.e. where are you trying to download) or only on this? You might want to ask others to confirm this.
  • Does this work fine in IE / Safari or in another browser? You can even try to do this using wget or curl from the command line or something like that.
  • Are you providing the Content-Type header correctly?
  • Can you try loading another file or a file of a different type, for example. a .png or .xls ? In fact, perhaps the easiest would be to try a simple text file ( text/plain ), and then take it from there.

Hope this helps.

+4
source share

I know this is a very old question, but I had the same problem. The solution is either

  • Encode your file name for RFC2184 or
  • If you do not have special characters in the name of your file, specify it in the content placement line.

Since you've already tried 2, you can try using 1 and see how it works.

I usually use the ContentDisposition class to create my title for me:

 Dim contentDispositionHeader = New Net.Mime.ContentDisposition() With {.FileName = filename} Response.AddHeader("Content-Disposition", contentDispositionHeader.ToString()) 

Hope this helps.

+4
source share

All Articles