浏览器和 Postman 不解码 Content-Disposition 标头中的 UTF-8 文件名。

huangapple go评论79阅读模式
英文:

Browsers and Postman doesn't decode UTF-8 filename in Content-Disposition header

问题

  1. 返回 Content-Disposition: attachment; filename="привет.txt"
  2. 返回 Content-Disposition: attachment; filename*=UTF-8''%some%encoded%name.txt"
    两种方法都不能在Postman/浏览器中正常工作,但第二种方法在Swagger中可以正常工作。第一种方法返回类似于Content-Disposition: attachment; filename="???.txt"的内容。第二种方法返回完全相同的文件名文本,使用UTF-8编码,例如:UTF-8''%some%encoded%name.txt。我正在使用Java Spring技术栈。
英文:

so I have the situation when I need to return CSV/excel file on a POST request. The problem is to return the filename in different languages, such as Chinese, German, etc. As far as I know, there're 2 ways to do that:

  1. to return Content-Disposition: attachment; filename="привет.txt"
  2. to return Content-Disposition: attachment; filename*=UTF-8''%some%encoded%name.txt".

Both of them do not work with Postman/Browser, but the second one works fine with Swagger. The first way returns something like this Content-Disposition: attachment; filename="???.txt". The second one returns absolutely the same text of filename quotes (encoded UTF-8, for instance: UTF-8''%some%encoded%name.txt. I'm using Java Spring stack.

答案1

得分: 0

所以答案是通过在UI部分处理那个Content-Disposition头部,在UTF-8''符号后进行编码。

英文:

So the answer was to process that Content-Disposition header on the UI part by encoding it after UTF-8'' symbols.

huangapple
  • 本文由 发表于 2020年9月18日 20:05:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/63955447.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定