提交 73bb822d 编写于 作者: H haoxr

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

上级 3ddbe68a
......@@ -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);
}
......
......@@ -23,7 +23,7 @@ public interface FileService {
/**
* 删除文件
*
* @param filePath
* @param filePath 文件路径
* @return
*/
boolean deleteFile(String filePath);
......
......@@ -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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册