Browse Source

将获取文件的接口做额外的处理4

Yangzw 1 month ago
parent
commit
a92fd7c94d

+ 6 - 4
feifan-framework/feifan-common/src/main/java/cn/newfeifan/mall/framework/common/util/servlet/ServletUtils.java

@@ -22,6 +22,8 @@ import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.util.Map;
 
+import static cn.hutool.core.io.FileUtil.getAbsolutePath;
+
 /**
  * 客户端工具类
  *
@@ -72,9 +74,9 @@ public class ServletUtils {
      * @param reqRange range
      * @param response 响应体
      */
-    public static void transfer(byte[] content, String reqRange, HttpServletResponse response){
+    public static void transfer(byte[] content, String reqRange, HttpServletResponse response,String path){
         try {
-            File sf = fileTransition(content);
+            File sf = fileTransition(content,path);
             log.info("=====file文件:{}",sf);
             RspInfo ri= getPartFileRsp( sf, reqRange) ;
             response.setContentLength((int)ri.content_Length);
@@ -154,8 +156,8 @@ public class ServletUtils {
      * @return file
      * @throws IOException 异常
      */
-    public static File fileTransition(byte[] content) throws IOException{
-        File file = new File("data/file/videoTest.mp4");
+    public static File fileTransition(byte[] content,String path) throws IOException{
+        File file = new File(getAbsolutePath(path));
         log.info("======file:{}",file);
         if(!file.exists()){
             boolean newFile = file.createNewFile();

+ 2 - 1
feifan-module-infra/feifan-module-infra-biz/src/main/java/cn/newfeifan/mall/module/infra/controller/admin/file/FileController.java

@@ -73,6 +73,7 @@ public class FileController {
         }
         // 解码,解决中文路径的问题 https://gitee.com/zhijiantianya/ruoyi-vue-pro/pulls/807/
         path = URLUtil.decode(path);
+        log.info("=====path:{}",path);
 
         // 读取内容
         byte[] content = fileService.getFileContent(configId, path);
@@ -84,7 +85,7 @@ public class FileController {
         if (path.contains("mp4")) {
             String range = request.getHeader("Range");
             log.info("========Range:{}", range);
-            ServletUtils.transfer(content, range, response);
+            ServletUtils.transfer(content, range, response,path);
         } else {
             log.info("===============开始获取文件");
             ServletUtils.writeAttachment(response, path, content, request);