From 73bb822d5d8fc810672e3a96d3bdff95c44ebde1 Mon Sep 17 00:00:00 2001 From: haoxr <1490493387@qq.com> Date: Tue, 22 Nov 2022 00:27:27 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=88=A0=E9=99=A4=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E6=8E=A5=E5=8F=A3=E5=85=A5=E5=8F=82=E7=94=B1=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=90=8D=E4=BF=AE=E6=94=B9=E4=B8=BA=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=AE=8C=E6=95=B4=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../file/controller/FileController.java | 4 ++-- .../common/file/service/FileService.java | 2 +- .../file/service/impl/MinioServiceImpl.java | 23 +++++++++++++++---- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/youlai-common/common-file/src/main/java/com/youlai/common/file/controller/FileController.java b/youlai-common/common-file/src/main/java/com/youlai/common/file/controller/FileController.java index 346c72405..6b22aa70d 100644 --- a/youlai-common/common-file/src/main/java/com/youlai/common/file/controller/FileController.java +++ b/youlai-common/common-file/src/main/java/com/youlai/common/file/controller/FileController.java @@ -31,9 +31,9 @@ public class FileController { @ApiOperation(value = "文件删除") @SneakyThrows public Result deleteFile( - @ApiParam("文件路径") @RequestParam String fileName + @ApiParam("文件路径") @RequestParam String filePath ) { - boolean result = fileService.deleteFile(fileName); + boolean result = fileService.deleteFile(filePath); return Result.judge(result); } diff --git a/youlai-common/common-file/src/main/java/com/youlai/common/file/service/FileService.java b/youlai-common/common-file/src/main/java/com/youlai/common/file/service/FileService.java index 72e61106c..e03a42a42 100644 --- a/youlai-common/common-file/src/main/java/com/youlai/common/file/service/FileService.java +++ b/youlai-common/common-file/src/main/java/com/youlai/common/file/service/FileService.java @@ -23,7 +23,7 @@ public interface FileService { /** * 删除文件 * - * @param filePath + * @param filePath 文件路径 * @return */ boolean deleteFile(String filePath); diff --git a/youlai-common/common-file/src/main/java/com/youlai/common/file/service/impl/MinioServiceImpl.java b/youlai-common/common-file/src/main/java/com/youlai/common/file/service/impl/MinioServiceImpl.java index 45d4b2087..def19f10a 100644 --- a/youlai-common/common-file/src/main/java/com/youlai/common/file/service/impl/MinioServiceImpl.java +++ b/youlai-common/common-file/src/main/java/com/youlai/common/file/service/impl/MinioServiceImpl.java @@ -73,6 +73,12 @@ public class MinioServiceImpl implements FileService, InitializingBean { } + /** + * 上传文件 + * + * @param file 表单文件对象 + * @return + */ @Override @SneakyThrows public FileInfo uploadFile(MultipartFile file) { @@ -109,17 +115,26 @@ public class MinioServiceImpl implements FileService, InitializingBean { fileUrl = customDomain + '/' + bucketName + "/" + fileName; } - FileInfo fileInfo=new FileInfo(); + FileInfo fileInfo = new FileInfo(); fileInfo.setName(fileName); fileInfo.setUrl(fileUrl); return fileInfo; } - - + /** + * 删除文件 + * + * @param filePath 文件路径 + * https://oss.youlai.tech/default/2022/11/20/test.jpg + * @return + */ @Override @SneakyThrows - public boolean deleteFile(String fileName) { + public boolean deleteFile(String filePath) { + Assert.notBlank(filePath, "删除文件路径不能为空"); + String tempStr = "/" + bucketName + "/"; + String fileName = filePath.substring(filePath.indexOf(tempStr) + tempStr.length()); // 2022/11/20/test.jpg + RemoveObjectArgs removeObjectArgs = RemoveObjectArgs.builder() .bucket(bucketName) .object(fileName)