minio文件上传

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;
    }

4、MinioUtils

minio工具类

5、StrConstant

StrConstant字符串常量

6、结果截图

6.1 postamn
6.2 结果
相关推荐
tERS ERTS几秒前
Spring Cloud gateway 路由规则
java
ZUNr1几秒前
手写一个迷你版 @Column:注解到底是怎么工作的?
java
Treh UNFO6 分钟前
MySQL中的通配符
java
AI茶水间管理员6 分钟前
线程池核心线程数设为 0 会怎样?(附源码解析)
java·后端·面试
白开水都有人用7 分钟前
点击数据行选中复选框-抽离公共方法
java·前端·html
NE_STOP10 分钟前
SpringCloud进阶--Redis与分布式
java
MiNG MENS12 分钟前
Spring Boot 实战篇(四):实现用户登录与注册功能
java·spring boot·后端
是码龙不是码农14 分钟前
synchronized 底层原理深度详解
java·synchronized
邂逅星河浪漫15 分钟前
【Java】@EqualsAndHashCode 注解解析
java·开发语言
StackNoOverflow20 分钟前
Spring Data Redis 详解
java·redis·spring