直接去官网下载: https://docs.min.io/docs/minio-quickstart-guide.html
启动minio进入 minio.exe 所在文件夹,地址栏输入cmd打开CMD窗口,输入下面的命令
.minio.exe server E:minio
浏览器输入 http://127.0.0.1:9000/,Access Key 和 Secret Key 在命令行那有显示,都是 minioadmin
SpringBoot整合Minioio.minio minio8.0.3
server: port: 10002 spring: servlet: multipart: max-file-size: 100MB max-request-size: 100MB # minio minio: endpoint: http://localhost:9000 accessKey: minioadmin secretKey: minioadmin bucketName: file
package com.example.config; @Configuration public class MinIoClientConfig { @Value("${minio.endpoint}") private String endpoint; @Value("${minio.accessKey}") private String accessKey; @Value("${minio.secretKey}") private String secretKey; @Bean public MinioClient minioClient() { return MinioClient.builder() .endpoint(endpoint) .credentials(accessKey, secretKey) .build(); } }
package com.example.utils; @Component @Slf4j public class MinioUtil { @Resource private MinioClient minioClient; @Resource private CustomMinioClient customMinioClient; @Value("${minio.bucketName}") private String bucketName; public FileDTO uploadFile(MultipartFile file) throws Exception { String fileName = file.getOriginalFilename(); // 上传文件路径 String rename = RenameUtil.generateFileName(fileName); String objectName = RenameUtil.getFilePath(rename); PutObjectArgs objectArgs = PutObjectArgs.builder().object(objectName) .bucket(bucketName) .contentType(file.getContentType()) .stream(file.getInputStream(), file.getSize(), -1).build(); minioClient.putObject(objectArgs); return FileDTO.builder().bucketName(bucketName).objectName(objectName).originalFilename(fileName).build(); } public void downloadFile(HttpServletResponse res, String fileName) { GetObjectArgs objectArgs = GetObjectArgs.builder().bucket(bucketName) .object(fileName).build(); OutputStream outputStream = null; try (GetObjectResponse response = minioClient.getObject(objectArgs)) { outputStream = res.getOutputStream(); StreamUtils.copy(response, outputStream); res.setCharacterEncoding("utf-8"); res.setContentType("application/force-download");// 设置强制下载不打开 res.addHeader("Content-Disposition", "attachment;fileName=" + fileName); } catch (Exception e) { e.printStackTrace(); } finally { IoUtil.close(outputStream); } } }
package com.example.controller; @RestController public class UploadController { @Resource private MinioUtil minioUtil; @PostMapping("/upload") public String upload(MultipartFile file) { if (ObjectUtil.isNull(file)) { return "文件不能为null"; } try { FileDTO fileDTO = minioUtil.uploadFile(file); return JSONUtil.toJsonStr(fileDTO); } catch (Exception e) { e.printStackTrace(); return "文件上传异常"; } } @GetMapping("/download") public void download(@RequestParam("filename") String filename, HttpServletResponse res) { minioUtil.downloadFile(res, filename); } }分片上传
分片上传去看这个demo 里面有代码仓库地址 https://blog.csdn.net/Tuine/article/details/113996848
如果你minio版本是3.0.X,应该是不支持分片上传的(反正我没有找到)
完整demo https://gitee.com/mental-patient-zhu-xx/minio
参考链接:
分片 https://blog.csdn.net/Tuine/article/details/113996848
工具类 https://blog.csdn.net/weixin_42170236/article/details/109356921
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)