From 3cbcab25321c3bf3a869cc2444ab7d3b8ea3cdd0 Mon Sep 17 00:00:00 2001 From: pengjie <17373303529@163.com> Date: Wed, 19 Jul 2023 16:56:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E6=94=B9?= =?UTF-8?q?=E5=8F=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/admin/FileController.java | 95 ++++++++++--------- 1 file changed, 48 insertions(+), 47 deletions(-) diff --git a/src/main/java/com/zhgd/xmgl/modules/basicdata/controller/admin/FileController.java b/src/main/java/com/zhgd/xmgl/modules/basicdata/controller/admin/FileController.java index ab72719..f5d781d 100644 --- a/src/main/java/com/zhgd/xmgl/modules/basicdata/controller/admin/FileController.java +++ b/src/main/java/com/zhgd/xmgl/modules/basicdata/controller/admin/FileController.java @@ -17,6 +17,7 @@ import org.springframework.web.multipart.MultipartFile; import springfox.documentation.annotations.ApiIgnore; import javax.servlet.http.HttpServletResponse; +import java.net.URLEncoder; import java.util.Map; /** @@ -41,25 +42,25 @@ public class FileController { /** * 上传文件到指定存储平台,成功返回文件信息 */ -// @OperLog(operModul = "文件管理", operType = "文件上传", operDesc = "文件上传") -// @ApiOperation(value = "文件上传", notes = "文件上传", httpMethod="POST") -// @PostMapping("/upload") -// public Result uploadPlatform(MultipartFile file) { -// return Result.success(fileStorageService.of(file) -// .setPlatform("minio-1") //使用指定的存储平台 -// .upload()); -// } - - /** - * 上传文件到本地,成功返回文件信息 - */ @OperLog(operModul = "文件管理", operType = "文件上传", operDesc = "文件上传") @ApiOperation(value = "文件上传", notes = "文件上传", httpMethod="POST") @PostMapping("/upload") - public Result> upload(MultipartFile file) { - return Result.success(fileDetailService.upload(file)); + public Result uploadPlatform(MultipartFile file) { + return Result.success(fileStorageService.of(file) + .setPlatform("minio-1") //使用指定的存储平台 + .upload()); } +// /** +// * 上传文件到本地,成功返回文件信息 +// */ +// @OperLog(operModul = "文件管理", operType = "文件上传", operDesc = "文件上传") +// @ApiOperation(value = "文件上传", notes = "文件上传", httpMethod="POST") +// @PostMapping("/upload") +// public Result> upload(MultipartFile file) { +// return Result.success(fileDetailService.upload(file)); +// } + /** * 上传BASE64文件 */ @@ -79,38 +80,21 @@ public class FileController { /** * 下载文件 */ -// @OperLog(operModul = "文件管理", operType = "文件下载", operDesc = "文件下载") -// @ApiOperation(value = "文件下载", notes = "文件下载", httpMethod="POST") -// @ApiImplicitParam(name = "fileUrl", value = "文件路径", paramType = "body", dataType = "String") -// @PostMapping("/download") -// public void download(@ApiIgnore @RequestBody Map map, HttpServletResponse response) throws Exception { -// // 获取文件信息 -// String fileUrl = MapUtils.getString(map, "fileUrl"); -// FileInfo fileInfo = fileStorageService.getFileInfoByUrl(fileUrl); -// if (null == fileInfo) { -// throw new Exception("缩略图文件下载失败,文件不存在!fileInfo:" + fileInfo); -// } -// response.setHeader("Content-disposition", "attachment; filename=" + fileUrl.substring(fileUrl.lastIndexOf("/") + 1)); -// response.setContentType("application/octet-stream");// 定义输出类型 -// fileStorageService.download(fileInfo).outputStream(response.getOutputStream()); -// } - - /** - * 获取预览文件流 - */ -// @OperLog(operModul = "文件管理", operType = "获取预览文件流", operDesc = "获取预览文件流") -// @ApiOperation(value = "获取预览文件流", notes = "获取预览文件流", httpMethod="POST") -// @GetMapping("/preview") -// public void download(@RequestParam(value = "fileUrl", required = true) String fileUrl, HttpServletResponse response) throws Exception { -// // 获取文件信息 -// FileInfo fileInfo = fileStorageService.getFileInfoByUrl(fileUrl); -// if (null == fileInfo) { -// throw new Exception("缩略图文件预览失败,文件不存在!fileInfo:" + fileInfo); -// } -// response.setHeader("Content-disposition", "attachment; filename=" + URLEncoder.encode(fileInfo.getOriginalFilename(), "UTF-8")); -// response.setContentType("application/octet-stream");// 定义输出类型 -// fileStorageService.download(fileInfo).outputStream(response.getOutputStream()); -// } + @OperLog(operModul = "文件管理", operType = "文件下载", operDesc = "文件下载") + @ApiOperation(value = "文件下载", notes = "文件下载", httpMethod="POST") + @ApiImplicitParam(name = "fileUrl", value = "文件路径", paramType = "body", dataType = "String") + @PostMapping("/download") + public void download(@ApiIgnore @RequestBody Map map, HttpServletResponse response) throws Exception { + // 获取文件信息 + String fileUrl = MapUtils.getString(map, "fileUrl"); + FileInfo fileInfo = fileStorageService.getFileInfoByUrl(fileUrl); + if (null == fileInfo) { + throw new Exception("缩略图文件下载失败,文件不存在!fileInfo:" + fileInfo); + } + response.setHeader("Content-disposition", "attachment; filename=" + fileUrl.substring(fileUrl.lastIndexOf("/") + 1)); + response.setContentType("application/octet-stream");// 定义输出类型 + fileStorageService.download(fileInfo).outputStream(response.getOutputStream()); + } /** * 获取预览文件流 @@ -120,6 +104,23 @@ public class FileController { @GetMapping("/preview") public void download(@RequestParam(value = "fileUrl", required = true) String fileUrl, HttpServletResponse response) throws Exception { // 获取文件信息 - fileDetailService.download(fileUrl, response); + FileInfo fileInfo = fileStorageService.getFileInfoByUrl(fileUrl); + if (null == fileInfo) { + throw new Exception("缩略图文件预览失败,文件不存在!fileInfo:" + fileInfo); + } + response.setHeader("Content-disposition", "attachment; filename=" + URLEncoder.encode(fileInfo.getOriginalFilename(), "UTF-8")); + response.setContentType("application/octet-stream");// 定义输出类型 + fileStorageService.download(fileInfo).outputStream(response.getOutputStream()); } + + /** + * 获取预览文件流 + */ +// @OperLog(operModul = "文件管理", operType = "获取预览文件流", operDesc = "获取预览文件流") +// @ApiOperation(value = "获取预览文件流", notes = "获取预览文件流", httpMethod="POST") +// @GetMapping("/preview") +// public void download(@RequestParam(value = "fileUrl", required = true) String fileUrl, HttpServletResponse response) throws Exception { +// // 获取文件信息 +// fileDetailService.download(fileUrl, response); +// } }