当前位置: 代码迷 >> 综合 >> MinIO spring boot starter 1.0.0 项目中存储获取文件
  详细解决方案

MinIO spring boot starter 1.0.0 项目中存储获取文件

热度:11   发布时间:2024-01-25 12:40:10.0

MinIO spring boot starter 是为 minio 在springboot项目中使用而编写的springboot starter,具有一般项目中使用到的文件存储获取功能,计划在后续版本将添加操作minIO的更多功能。

简介

  1. 使用minIO单bucket存储获取对象(文件)
  2. 也可以获取对象输入流、直接写入输出流

使用方法:

依赖

<dependency><groupId>com.jvm123</groupId><artifactId>minio-spring-boot-starter</artifactId><version>1.0.0</version>
</dependency>

配置

file:store:minio:endpoint: http://petdy.cn:9000bucket: test-bucketaccess-key: adminsecret-key: admintmp-dir: ./tmp/

使用

package com.jvm123.demo;import com.jvm123.minio.service.FileStoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;/*** @author yawn http://jvm123.com* 2020/1/15 17:17*/
@RestController
public class TestController {@AutowiredFileStoreService fileStoreService;@GetMapping("get")public void get(HttpServletResponse response) throws IOException {// 存储文件fileStoreService.save(new File("C:\\asd.txt"), "a.txt");// 获取文件File file = fileStoreService.getFile("a.txt");// 获取输入流InputStream inputStream = fileStoreService.getStream("a.txt");// 下载response.addHeader("Content-Disposition","attachment;filename=a.txt");ServletOutputStream os = response.getOutputStream();fileStoreService.download("a.txt", os);}
}

change list

v1.0.0 常用功能的实现

  1. 实现使用minIO单bucket存储获取对象(文件)的功能
  2. 实现获取对象输入流、写入输出流等功能

原文连接: http://jvm123.com/2020/01/minio-spring-boot.html

  相关解决方案