From eb7c29c647df5f3aa335f5075e78fdf7c675079d Mon Sep 17 00:00:00 2001 From: 疯狂的狮子li <15040126243@163.com> Date: 星期四, 18 六月 2020 15:33:36 +0800 Subject: [PATCH] 解决文件上传bug,因undertow与tomcat对文件写入的底层实现不同,无需创建新文件 --- ruoyi/src/main/java/com/ruoyi/project/common/CommonController.java | 20 ++++++++++++++++++++ 1 files changed, 20 insertions(+), 0 deletions(-) diff --git a/ruoyi/src/main/java/com/ruoyi/project/common/CommonController.java b/ruoyi/src/main/java/com/ruoyi/project/common/CommonController.java index b9c3937..b900b74 100644 --- a/ruoyi/src/main/java/com/ruoyi/project/common/CommonController.java +++ b/ruoyi/src/main/java/com/ruoyi/project/common/CommonController.java @@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; +import com.ruoyi.common.constant.Constants; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.file.FileUploadUtils; import com.ruoyi.common.utils.file.FileUtils; @@ -86,4 +87,23 @@ return AjaxResult.error(e.getMessage()); } } + + /** + * 鏈湴璧勬簮閫氱敤涓嬭浇 + */ + @GetMapping("/common/download/resource") + public void resourceDownload(String name, HttpServletRequest request, HttpServletResponse response) throws Exception + { + // 鏈湴璧勬簮璺緞 + String localPath = RuoYiConfig.getProfile(); + // 鏁版嵁搴撹祫婧愬湴鍧� + String downloadPath = localPath + StringUtils.substringAfter(name, Constants.RESOURCE_PREFIX); + // 涓嬭浇鍚嶇О + String downloadName = StringUtils.substringAfterLast(downloadPath, "/"); + response.setCharacterEncoding("utf-8"); + response.setContentType("multipart/form-data"); + response.setHeader("Content-Disposition", + "attachment;fileName=" + FileUtils.setFileDownloadHeader(request, downloadName)); + FileUtils.writeBytes(downloadPath, response.getOutputStream()); + } } -- Gitblit v1.9.3