From 66f453452e3fd0985c581d762d63feccaef08d8e Mon Sep 17 00:00:00 2001
From: 疯狂的狮子li <15040126243@163.com>
Date: 星期四, 24 六月 2021 15:41:16 +0800
Subject: [PATCH] fix 相对路径下载问题

---
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java |   20 ++++++++++++--------
 1 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java
index c69cdf2..d61f99f 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java
@@ -18,10 +18,13 @@
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
 
 /**
  * 閫氱敤璇锋眰澶勭悊
- * 
+ *
  * @author ruoyi
  */
 @RestController
@@ -34,7 +37,7 @@
 
     /**
      * 閫氱敤涓嬭浇璇锋眰
-     * 
+     *
      * @param fileName 鏂囦欢鍚嶇О
      * @param delete 鏄惁鍒犻櫎
      */
@@ -49,13 +52,13 @@
             }
             String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
             String filePath = RuoYiConfig.getDownloadPath() + fileName;
-
+			File file = new File(filePath);
             response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
             FileUtils.setAttachmentResponseHeader(response, realFileName);
-            FileUtils.writeBytes(filePath, response.getOutputStream());
+			FileUtils.writeToStream(file, response.getOutputStream());
             if (delete)
             {
-                FileUtils.deleteFile(filePath);
+				FileUtils.del(file);
             }
         }
         catch (Exception e)
@@ -77,10 +80,10 @@
             // 涓婁紶骞惰繑鍥炴柊鏂囦欢鍚嶇О
             String fileName = FileUploadUtils.upload(filePath, file);
             String url = serverConfig.getUrl() + fileName;
-            AjaxResult ajax = AjaxResult.success();
+			Map<String,Object> ajax = new HashMap<>();
             ajax.put("fileName", fileName);
             ajax.put("url", url);
-            return ajax;
+            return AjaxResult.success(ajax);
         }
         catch (Exception e)
         {
@@ -108,8 +111,9 @@
             // 涓嬭浇鍚嶇О
             String downloadName = StrUtil.subAfter(downloadPath, "/",true);
             response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
+			File file = new File(downloadPath);
             FileUtils.setAttachmentResponseHeader(response, downloadName);
-            FileUtils.writeBytes(downloadPath, response.getOutputStream());
+            FileUtils.writeToStream(file, response.getOutputStream());
         }
         catch (Exception e)
         {

--
Gitblit v1.9.3