【7.0.4】【util】新增一个下载文件设置头的工具类

pull/22/head
fengshuonan 2021-07-01 15:04:53 +08:00
parent 5a06086b96
commit 6704c5a5db
1 changed files with 15 additions and 0 deletions

View File

@ -25,6 +25,9 @@
package cn.stylefeng.roses.kernel.rule.util;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.URLUtil;
import cn.hutool.http.ContentType;
import cn.stylefeng.roses.kernel.rule.pojo.response.ErrorResponseData;
import com.alibaba.fastjson.JSON;
@ -79,4 +82,16 @@ public class ResponseRenderUtil {
}
}
/**
*
*
* @author fengshuonan
* @date 2021/7/1 15:01
*/
public static void setRenderFileHeader(HttpServletResponse response, String fileName) {
final String charset = ObjectUtil.defaultIfNull(response.getCharacterEncoding(), CharsetUtil.UTF_8);
response.setHeader("Content-Disposition", StrUtil.format("attachment;filename={}", URLUtil.encode(fileName, charset)));
response.setContentType("application/octet-stream; charset=utf-8");
}
}