I have been trying to download an attachment with a Chinese filename but somehow their encoding changes to some gibberish filename while downloading.
Here's my code -
String fileName = "出口项目.zip";
final HttpHeaders headers = new HttpHeaders();
headers.setContentDisposition(ContentDisposition
.builder("attachment")
.filename(fileName).build());
return ResponseEntity.ok()
.contentType(MediaType.APPLICATION_OCTET_STREAM)
.headers(headers)
.body(fileInputStreamResource);
I have already tried filename= URLEncoder.encode(fileName, "UTF-8");
and all other solutions available on Stack overflow but always get only 2 types of response-
- either the file name changes to '????.zip'.
- or if the encoded characters fall in ASCII then the filename is the encoded name. (eg: \u51FA\u53E3\u9879\u76EE.zip)
Technology used- Java 17 for Spring Boot and using Postman for requests.
Is there any way I can preserve the Chinese characters in Content-Disposition or any workaround?