refactor: 删除文件接口入参由文件名修改为文件完整路径
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user