Преглед на файлове

调整旧文件服务的下载方式,改为旧的下载方式

lijie преди 3 години
родител
ревизия
fbcb9e1408

+ 10 - 7
dmp-cloud/dmp-file/src/main/java/com/persagy/dmp/file/service/impl/CompatibleOldFileServiceImpl.java

@@ -28,6 +28,7 @@ import org.springframework.transaction.annotation.Transactional;
 
 import javax.servlet.http.HttpServletResponse;
 import java.io.InputStream;
+import java.net.URLEncoder;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -285,14 +286,16 @@ public class CompatibleOldFileServiceImpl implements CompatibleOldFileService {
             return;
         }
         // 3.通过文件流的方式下载文件
-        // IoUtil.copy(service.download(fileInfo.getFileBucket(),fileInfo.getFilePath()),response.getOutputStream());
+        IoUtil.copy(service.download(fileInfo.getFileBucket(),fileInfo.getFilePath()),response.getOutputStream());
+        response.setHeader(CommonConstant.REPONSE_HEAD_CONTENT_DISPOSITION,
+                CommonConstant.REPONSE_HEAD_CONTENT_DISPOSITION_ATTACHMENT + URLEncoder.encode(fileInfo.getFileName(), "UTF-8"));
         // 4.2021年12月22日12:00:21,先申请下载地址,然后通过重定向的方式直接请求文件服务器进行下载
-        String fetchUrl = service.fetchUrl(fileInfo.getFileBucket(), fileInfo.getFilePath());
-        if (StrUtil.isBlank(fetchUrl)){
-            IoUtil.writeUtf8(response.getOutputStream(),Boolean.FALSE,"File not existed");
-            return;
-        }
-        response.sendRedirect(fetchUrl);
+//        String fetchUrl = service.fetchUrl(fileInfo.getFileBucket(), fileInfo.getFilePath());
+//        if (StrUtil.isBlank(fetchUrl)){
+//            IoUtil.writeUtf8(response.getOutputStream(),Boolean.FALSE,"File not existed");
+//            return;
+//        }
+//        response.sendRedirect(fetchUrl);
     }
 
     /***

+ 8 - 0
dmp-common/src/main/java/com/persagy/dmp/common/constant/CommonConstant.java

@@ -54,4 +54,12 @@ public interface CommonConstant {
     String REMOVE_FIELD ="$remove";
     /** result字段 */
     String RESULT ="result";
+    /**响应头:Content-disposition*/
+    public static final String REPONSE_HEAD_CONTENT_DISPOSITION = "Content-disposition";
+    /**响应头:Content-Type*/
+    public static final String REPONSE_HEAD_CONTENT_TYPE = "Content-Type";
+    /**响应头:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet*/
+    public static final String REPONSE_HEAD_CONTENT_TYPE_SHEET = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
+    /**响应头:attachment;filename=*/
+    public static final String REPONSE_HEAD_CONTENT_DISPOSITION_ATTACHMENT = "attachment;filename=";
 }