我正在尝试下载名称为阿拉伯语言的文件。文件内容为阿拉伯文,但下载时名称已加密。
responseBuilder.header("Content-Disposition",
"attachment; filename=\"" + fileName + "\"; filename*=utf-8''" + URLEncoder
.encode(fileName, "UTF-8"));
这时的文件名是阿拉伯语,但在浏览器的响应中,头文件名已更改为其他内容,例如E1-(E1-(。txt
Http响应标题:
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
谢谢你。
好的,因此在UI端可以实现这一目标。
在响应头中,fileName *提供编码值,并在UI端使用以下JS方法解码该值:从字符串中删除utf8'',因此您将获得实际的文件名。
window.decodeURIComponent(t.substring(t.lastIndexOf('\'')+1,t.length));