HTTP 文件下载时中文文件名乱码问题处理

来源:互联网 发布:男生暗恋女生知乎 编辑:程序博客网 时间:2024/04/30 11:59

  之前有做文件下载处理,但由于文件名一直是英文的,所以并未发现有该问题,直到最近项目中有中文名出现.

  以前的代码设置:

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/

0 0
原创粉丝点击