英文:
Browsers and Postman doesn't decode UTF-8 filename in Content-Disposition header
问题
- 返回
Content-Disposition: attachment; filename="привет.txt"
。 - 返回
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:
- to return
Content-Disposition: attachment; filename="привет.txt"
- 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论