minio文件上传
1、controller
java
@PostMapping("/upload2minio")
public Response<List<Map<String,String>>> upload2minio(@RequestPart("req") FileUploadReq req, @RequestPart("fileList") List<MultipartFile> fileList){
req.setFileList(fileList);
return Response.builder(fileService.upload2minio(req));
}
2、service
java
/**
* @author: yc
* @des: 文件上传到minio
* @date: 2024/8/4 14:08
*/
List<Map<String,String>> upload2minio(FileUploadReq req);
3、serviceImpl
java
/**
* @author: yc
* @des: 文件上传到minio
* @date: 2024/8/4 14:08
*/
@Override
public List<Map<String, String>> upload2minio(FileUploadReq req) {
if(Objects.isNull(req)){
throw new BusinessException("请求参数不能为空");
}
if(CollectionUtils.isEmpty(req.getFileList())){
throw new BusinessException("上传文件不能为空");
}
String dir = null;
if(StringUtils.isNotBlank(req.getDirName1()) && StringUtils.isNotBlank(req.getDirName2())){
dir = MINIO_PUBLIC_DIR_PATH + StrConstant.SLASH + req.getDirName1() + StrConstant.SLASH + req.getDirName2();
}
else if(StringUtils.isNotBlank(req.getDirName1())){
dir = MINIO_PUBLIC_DIR_PATH + StrConstant.SLASH + req.getDirName1();
}
List<Map<String,String>> uploadList = new ArrayList<>();
for(MultipartFile multipartFile : req.getFileList()){
Map<String, String> map = MinioUtils.upload(multipartFile,dir);
uploadList.add(map);
}
return uploadList;
}