1

I know there are several versions of this question here, but I've tried as many of the recommendations in them as I can, yet it doesn't seem to work. Most of those suggest setting the Content-Disposition header item. From the JS frontend, I've set it using

Content-Disposition: attachment; filename=*"Dbase%20%20%20Emails%20-%20Copy.xlsx"; 
    filename="Dbase%20%20%20Emails%20-%20Copy.xlsx"
<or>
Content-Disposition: attachment; filename=*UTF-8''Dbase%20%20%20Emails%20-%20Copy.xlsx
<or>
encodeURI("Dbase   Emails - Copy.xlsx")
<or>
filename="Dbase   Emails - Copy.xlsx"

Or I've tried setting it on the response header, a golang backend, with pretty much the same form, but Firefox continues to ignore whatever is passed across in the header, and you see under "File" in the devtools a decoded: "Dbase Emails - Copy.xlsx" and in the response header, you see correctly, this:

attachment; filename=*"Dbase%20%20%20Emails%20-%20Copy.xlsx"; 
    filename="Dbase%20%20%20Emails%20-%20Copy.xlsx"

That seems right, what can I do to make Firefox download it as the correct name?

Thanks - Kev

I'd attempted all I could try from previous issues such as:

How to encode the filename parameter of Content-Disposition header in HTTP?

Drew Reese
  • 165,259
  • 14
  • 153
  • 181
kevmonstah
  • 11
  • 2

1 Answers1

0

For the current Firefox (version 111.0.1), hacking the Content-Disposition header does not help at all. Because Firefox will sanitize the filename and compress whitespaces.

I don't know why you want to keep the whitespaces, but please note that the filename parameter provides mostly indicative information, and all the browsers would sanitize the filename. For example, Chrome on Linux will replace / in the filename with _.

BTW, filename=*UTF-8 should be filename*=UTF-8.

References:

  1. Firefox source code that calls DownloadPaths.sanitize: https://hg.mozilla.org/mozilla-central/file/bce007ba1a3fdb155321a15a3430395dddbccb4a/toolkit/mozapps/downloads/HelperAppDlg.jsm#l428

    Note: The source code is not for the current version. But the behavior is the same.

  2. Some discussions on compressing whitespaces: https://bugzilla.mozilla.org/show_bug.cgi?id=1637973

  3. The Content-Disposition header: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition

Zeke Lu
  • 6,349
  • 1
  • 17
  • 23
  • Thanks for the response. Well, I suppose that's kind of a depressing answer about the behavior. Would want to keep the spaces as that's what a user wants. Saved the file as "NA ME", they want it to remain "NA ME", not become "NA ME". – kevmonstah Apr 01 '23 at 18:45
  • A workaround is modify the server code to zip the file so that you can keep the name untouched. – Zeke Lu Apr 01 '23 at 22:53