Jelajahi Sumber

文件上传代码

gaoxiong 2 tahun lalu
induk
melakukan
eff42fb360

+ 16 - 5
soc-modules/soc-modules-file/src/main/java/com/xunmei/file/controller/SysFileController.java

@@ -9,10 +9,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletResponse;
@@ -96,7 +93,21 @@ public class SysFileController
             log.error("下载文件失败", e);
             throw new RuntimeException(e);
         }
+    }
 
-
+    /**
+     * 路径参数
+     * @param response
+     * @param code
+     */
+    @GetMapping("/getFile/{code}")
+    public void getFile(HttpServletResponse response, @PathVariable String code){
+        try {
+            String filePath = DesUtil.decode(code, secretKey);
+            sysFileService.downloadFile(response,filePath);
+        } catch (Exception e) {
+            log.error("下载文件失败", e);
+            throw new RuntimeException(e);
+        }
     }
 }