mirror of
https://gitee.com/youlaitech/youlai-mall.git
synced 2024-12-23 05:00:25 +08:00
refactor: 删除文件接口入参由文件名修改为文件完整路径
This commit is contained in:
parent
3ddbe68a29
commit
73bb822d5d
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ public interface FileService {
|
|||||||
/**
|
/**
|
||||||
* 删除文件
|
* 删除文件
|
||||||
*
|
*
|
||||||
* @param filePath
|
* @param filePath 文件路径
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
boolean deleteFile(String filePath);
|
boolean deleteFile(String filePath);
|
||||||
|
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user