mirror of
				https://github.com/dromara/RuoYi-Vue-Plus.git
				synced 2025-11-04 08:13:44 +08:00 
			
		
		
		
	fix 修复跨域访问无权限获取请求头 download-filename 导致文件名为空问题
This commit is contained in:
		@@ -98,8 +98,6 @@ public class SysOssController extends BaseController {
 | 
			
		||||
            throw new ServiceException("文件数据不存在!");
 | 
			
		||||
        }
 | 
			
		||||
        response.reset();
 | 
			
		||||
        response.addHeader("Access-Control-Allow-Origin", "*");
 | 
			
		||||
        response.addHeader("Access-Control-Expose-Headers", "Content-Disposition");
 | 
			
		||||
        FileUtils.setAttachmentResponseHeader(response, sysOss.getOriginalName());
 | 
			
		||||
        response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE + "; charset=UTF-8");
 | 
			
		||||
        long data;
 | 
			
		||||
 
 | 
			
		||||
@@ -22,6 +22,9 @@ public class FileUtils extends FileUtil {
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    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);
 | 
			
		||||
 | 
			
		||||
        StringBuilder contentDispositionValue = new StringBuilder();
 | 
			
		||||
 
 | 
			
		||||
@@ -42,8 +42,6 @@ public class ExcelUtil {
 | 
			
		||||
		try {
 | 
			
		||||
			String filename = encodingFilename(sheetName);
 | 
			
		||||
			response.reset();
 | 
			
		||||
			response.addHeader("Access-Control-Allow-Origin", "*");
 | 
			
		||||
			response.addHeader("Access-Control-Expose-Headers", "Content-Disposition");
 | 
			
		||||
			FileUtils.setAttachmentResponseHeader(response, filename);
 | 
			
		||||
			response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8");
 | 
			
		||||
			ServletOutputStream os = response.getOutputStream();
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user