Encrypted file name on download and not in expected language i.e. Arabic

Viewed 331

I am trying to download file whose name is in Arabic language. Content of file is in arabic but name gets encrypted on download.

responseBuilder.header("Content-Disposition",
                                "attachment; filename=\"" + fileName + "\"; filename*=utf-8''" + URLEncoder
                                        .encode(fileName, "UTF-8"));

fileName at this point is in Arabic language but on browser's response Header fileName gets changed to something else like E1-(E1-(.txt

Http Response Header:

HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 10
Content-encoding: gzip
Connection: keep-alive
Cache-Control: private
Content-Disposition: attachment; filename="E1-(E1-(.txt.txt"; 
filename*=utf-8''%D9%85%D8%B1%D8%AD%D8%A8%D8%A7.txt
Expires: Mon, 26 Jul 1997 05:00:00 GMT
X-Backend: supra-prod-pdx-ff4d74bff-7srf7
X-Content-Type-Options: nosniff
X-Robots-Tag: noindex
X-Slack-Meta: proxy

Thank you in advance.

1 Answers

OKay, so at the UI side one can achieve this.

In the Response Header, fileName* provide the encoded value and at the UI end decode the value using following JS method: remove utf8'' from the string, so you'll get the actual file name.

window.decodeURIComponent(t.substring(t.lastIndexOf('\'')+1,t.length));
Related