Search code examples
javahttputf-8filenamescontent-disposition

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


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.


Solution

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