From c531d3e72e65b16650085567b4efc0b157f8d3a7 Mon Sep 17 00:00:00 2001 From: haoxr <1490493387@qq.com> Date: Tue, 22 Nov 2022 00:30:09 +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 --- .../system/controller/FileController.java | 4 ++-- .../system/service/impl/MinioServiceImpl.java | 21 ++++++++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/youlai/system/controller/FileController.java b/src/main/java/com/youlai/system/controller/FileController.java index b805a1ed..ea602b19 100644 --- a/src/main/java/com/youlai/system/controller/FileController.java +++ b/src/main/java/com/youlai/system/controller/FileController.java @@ -32,9 +32,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/src/main/java/com/youlai/system/service/impl/MinioServiceImpl.java b/src/main/java/com/youlai/system/service/impl/MinioServiceImpl.java index aaaba9d9..176b7957 100644 --- a/src/main/java/com/youlai/system/service/impl/MinioServiceImpl.java +++ b/src/main/java/com/youlai/system/service/impl/MinioServiceImpl.java @@ -72,7 +72,12 @@ public class MinioServiceImpl implements FileService, InitializingBean { .build(); } - + /** + * 上传文件 + * + * @param file 表单文件对象 + * @return + */ @Override @SneakyThrows public FileInfo uploadFile(MultipartFile file) { @@ -116,10 +121,20 @@ public class MinioServiceImpl implements FileService, InitializingBean { } - + /** + * 删除文件 + * + * @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)