下载文件时向header中添加filename参数

This commit is contained in:
Zhaoyang 2020-03-07 18:30:42 +08:00
parent 2da863a475
commit 12fff621ca
1 changed files with 3 additions and 0 deletions

View File

@ -14,6 +14,8 @@ import org.springframework.web.multipart.MultipartHttpServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -162,6 +164,7 @@ public class HttpHelper {
response.setContentType(getContextType(fileName));
response.setHeader("Content-disposition", "attachment; filename="+ fileName);
response.setHeader("Content-Length", String.valueOf(fileLength));
response.setHeader("filename", URLEncoder.encode(exportFileName, StandardCharsets.UTF_8.name()));
bis = new BufferedInputStream(new FileInputStream(localFilePath));
bos = new BufferedOutputStream(response.getOutputStream());
byte[] buff = new byte[2048];