fix 修复跨域访问无权限获取请求头 download-filename 导致文件名为空问题

This commit is contained in:
疯狂的狮子li 2021-10-22 12:38:33 +08:00
parent 296e6171a1
commit b8a8b76c38
3 changed files with 3 additions and 4 deletions

View File

@ -98,8 +98,6 @@ public class SysOssController extends BaseController {
throw new ServiceException("文件数据不存在!"); throw new ServiceException("文件数据不存在!");
} }
response.reset(); response.reset();
response.addHeader("Access-Control-Allow-Origin", "*");
response.addHeader("Access-Control-Expose-Headers", "Content-Disposition");
FileUtils.setAttachmentResponseHeader(response, sysOss.getOriginalName()); FileUtils.setAttachmentResponseHeader(response, sysOss.getOriginalName());
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE + "; charset=UTF-8"); response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE + "; charset=UTF-8");
long data; long data;

View File

@ -22,6 +22,9 @@ public class FileUtils extends FileUtil {
* @return * @return
*/ */
public static void setAttachmentResponseHeader(HttpServletResponse response, String realFileName) throws UnsupportedEncodingException { public static void setAttachmentResponseHeader(HttpServletResponse response, String realFileName) throws UnsupportedEncodingException {
response.addHeader("Access-Control-Allow-Origin", "*");
response.addHeader("Access-Control-Expose-Headers", "Content-Disposition,download-filename");
String percentEncodedFileName = percentEncode(realFileName); String percentEncodedFileName = percentEncode(realFileName);
StringBuilder contentDispositionValue = new StringBuilder(); StringBuilder contentDispositionValue = new StringBuilder();

View File

@ -42,8 +42,6 @@ public class ExcelUtil {
try { try {
String filename = encodingFilename(sheetName); String filename = encodingFilename(sheetName);
response.reset(); response.reset();
response.addHeader("Access-Control-Allow-Origin", "*");
response.addHeader("Access-Control-Expose-Headers", "Content-Disposition");
FileUtils.setAttachmentResponseHeader(response, filename); FileUtils.setAttachmentResponseHeader(response, filename);
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8"); response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8");
ServletOutputStream os = response.getOutputStream(); ServletOutputStream os = response.getOutputStream();