|
@@ -4,6 +4,7 @@ import java.io.IOException;
|
|
|
import java.util.List;
|
|
|
import java.util.Set;
|
|
|
|
|
|
+import com.ruoyi.common.config.RuoYiConfig;
|
|
|
import com.ruoyi.common.constant.Constants;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
import com.ruoyi.common.utils.file.FileUploadUtils;
|
|
@@ -11,6 +12,7 @@ import com.ruoyi.system.domain.SysRepoHistory;
|
|
|
import com.ruoyi.common.utils.OfficeCompareUtils;
|
|
|
import com.ruoyi.system.service.ISysRepoHistoryService;
|
|
|
import com.ruoyi.common.utils.file.FileUtils;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
@@ -148,22 +150,24 @@ public class SysRepoController extends BaseController
|
|
|
/**
|
|
|
* 文件下载
|
|
|
*/
|
|
|
- @GetMapping("/download/{resource}")
|
|
|
- public void resourceDownload(@PathVariable("resource") String resource, HttpServletRequest request, HttpServletResponse response)
|
|
|
- throws Exception
|
|
|
+ @GetMapping("/download")
|
|
|
+ public void Download(String file_path,String fileName, HttpServletRequest request, HttpServletResponse response)
|
|
|
{
|
|
|
-// // 本地资源路径
|
|
|
-// String localPath = getProfile();
|
|
|
-// // 数据库资源地址
|
|
|
-// String downloadPath = localPath + StringUtils.substringAfter(resource, Constants.RESOURCE_PREFIX);
|
|
|
- String downloadPath = "C:\\Users\\admin\\Desktop\\1.docx";
|
|
|
- // 下载名称
|
|
|
- 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());
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (!FileUtils.checkAllowDownload(fileName))
|
|
|
+ {
|
|
|
+ throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", file_path));
|
|
|
+ }
|
|
|
+ String filePath = RuoYiConfig.getUploadPath() + file_path;
|
|
|
+ response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
|
|
+ FileUtils.setAttachmentResponseHeader(response, fileName);
|
|
|
+ FileUtils.writeBytes(filePath, response.getOutputStream());
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ AjaxResult.error("下载文件失败", e);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|