Browse Source

feat:下载文件-响应头修改

Wangyafan 6 months ago
parent
commit
a380ede9d3

+ 5 - 2
src/main/java/com/sunxung/factoring/service/purchcontractmanagement/impl/PurchContractElectronicInfoServiceImpl.java

@@ -662,8 +662,11 @@ public class PurchContractElectronicInfoServiceImpl extends ServiceImpl<PurchCon
     public ResponseEntity<Object> downloadReportUrl(Long managementId, HttpServletResponse res) throws IOException {
         String fileName = "出证文件.zip";
         fileName = new String(fileName.getBytes("UTF-8"), "ISO8859-1");
-        res.setContentType("application/zip");
-        res.setHeader("Content-disposition", String.format("attachment; filename=" + fileName));
+//        res.setContentType("application/zip");
+//        res.setHeader("Content-Type", "application/vnd.ms-exce");
+//        res.setHeader("Content-Disposition", "attachment;filename=" + java.net.URLEncoder.encode(fileName, "UTF-8"));
+//        res.addHeader("Access-Control-Expose-Headers", "Content-Disposition");
+//        res.setHeader("Content-disposition", String.format("attachment; filename=" + fileName));
         PurchContractBasicInfo purchContractBasicInfo = purchContractBasicInfoService
                 .lambdaQuery().eq(PurchContractBasicInfo::getPurchContractManagementId,managementId).one();
         AttachmentDto attachmentDto = AttachmentDto.builder()

+ 4 - 1
src/main/java/com/sunxung/factoring/service/sys/impl/FileStorageServiceImpl.java

@@ -563,7 +563,10 @@ public class FileStorageServiceImpl implements FileStorageService {
                 String basePath = file.getAbsolutePath();
                 InputStream in = new FileInputStream(new File(basePath));
                 fileName = URLEncoder.encode(fileName, "UTF-8");
-                res.setHeader("content-disposition", "attachment;filename=" + fileName);
+//                res.setHeader("content-disposition", "attachment;filename=" + fileName);
+                res.setHeader("Content-Type", "application/vnd.ms-exce");
+                res.setHeader("Content-Disposition", "attachment;filename=" + java.net.URLEncoder.encode(fileName, "UTF-8"));
+                res.addHeader("Access-Control-Expose-Headers", "Content-Disposition");
                 OutputStream out = res.getOutputStream();
                 byte[] b = new byte[1024];
                 int len = -1;