How to set filename containing spaces in Content-Disposition header

后端 未结 4 1163
情话喂你
情话喂你 2020-12-09 14:20

I have this piece of code:

resp.addHeader(\"Content-Disposition\", \"inline; filename=\" + fileName);

When the file name is \"a_b_c.doc\" o

4条回答
  •  天命终不由人
    2020-12-09 15:06

    According to the HTTP standard you surround the string with double-quotes, and escape any quotes or backslashes within by preceding them with a single backslash.

    Content-Disposition: attachment; filename="Very \"interesting\" file \\ files.txt"
    

    This will prompt to save as Very "interesting" file \ files.txt. Note that the presence of a backslash does not suggest a folder, it suggests the backslash is part of the filename (which is perfectly valid on Linux and some other platforms, but not on Windows.)

提交回复
热议问题