文件明定义
RFC的标准做法是按照如下格式:
Content-Disposition: attachment;
filename="$encoded_fname";
filename*=utf-8''$encoded_fname
其中, $encoded_fname
指的是将 UTF-8 编码的原始文件名按照 RFC 3986 进行百分号编码(percent encoding)后得到的
java代码示例:
outputStream = response.getOutputStream();
String name = " 麦宝直播间配置文件";
String disposition = "attachment;filename*=utf-8'zh_cn'" + URLEncoder.encode(name, "utf-8");
response.setCharacterEncoding("utf-8");
response.setContentType("multipart/form-data");
response.setHeader("Content-Disposition", disposition);
空格encode之后变成+号的问题
需要在encode之后,手动对+号替换,替换回urlencode的空格,也就是%20
fileName.replaceAll("+","%20");