refactor: 删除文件接口入参由文件名修改为文件完整路径

This commit is contained in:
haoxr 2022-11-22 00:27:27 +08:00
parent 3ddbe68a29
commit 73bb822d5d
3 changed files with 22 additions and 7 deletions

View File

@ -31,9 +31,9 @@ public class FileController {
@ApiOperation(value = "文件删除") @ApiOperation(value = "文件删除")
@SneakyThrows @SneakyThrows
public Result deleteFile( 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); return Result.judge(result);
} }

View File

@ -23,7 +23,7 @@ public interface FileService {
/** /**
* 删除文件 * 删除文件
* *
* @param filePath * @param filePath 文件路径
* @return * @return
*/ */
boolean deleteFile(String filePath); boolean deleteFile(String filePath);

View File

@ -73,6 +73,12 @@ public class MinioServiceImpl implements FileService, InitializingBean {
} }
/**
* 上传文件
*
* @param file 表单文件对象
* @return
*/
@Override @Override
@SneakyThrows @SneakyThrows
public FileInfo uploadFile(MultipartFile file) { public FileInfo uploadFile(MultipartFile file) {
@ -109,17 +115,26 @@ public class MinioServiceImpl implements FileService, InitializingBean {
fileUrl = customDomain + '/' + bucketName + "/" + fileName; fileUrl = customDomain + '/' + bucketName + "/" + fileName;
} }
FileInfo fileInfo=new FileInfo(); FileInfo fileInfo = new FileInfo();
fileInfo.setName(fileName); fileInfo.setName(fileName);
fileInfo.setUrl(fileUrl); fileInfo.setUrl(fileUrl);
return fileInfo; return fileInfo;
} }
/**
* 删除文件
*
* @param filePath 文件路径
* https://oss.youlai.tech/default/2022/11/20/test.jpg
* @return
*/
@Override @Override
@SneakyThrows @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() RemoveObjectArgs removeObjectArgs = RemoveObjectArgs.builder()
.bucket(bucketName) .bucket(bucketName)
.object(fileName) .object(fileName)