之前有做文件下载处理,但由于文件名一直是英文的,所以并未发现有该问题,直到最近项目中有中文名出现.
以前的代码设置:
header['Content-Disposition'] = 'attachment; filename=\"'+result['out_filename']+'\"';
现在的代码设置:
result['out_filename'] = encodeURI(result['out_filename']);
header['Content-Disposition'] = "attachment; filename=\""+result['out_filename']+"\"; filename*=utf-8''"+result['out_filename'];
有两点说明一下:
1) 对应的文件名 encode一次
2) header中设置时多一个参数filename*=指定编码格式.....
参考文章地址:http://www.iefans.net/xiazai-wenjian-http-bianma-content-disposition/