简介
- 使用minIO单bucket存储获取删除对象(文件)
- 也可以获取对象输入流、直接写入输出流
- 支持多个bucket,也兼容v1.0.0的配置默认bucket
- 可创建和删除bucket
使用方法:
依赖
<dependency>
<groupId>com.jvm123</groupId>
<artifactId>minio-spring-boot-starter</artifactId>
<version>1.1.0</version>
</dependency>
配置
file:
store:
minio:
endpoint: http://192.168.80.106:9000
bucket: test
access-key: admin
secret-key: admin123
tmp-dir: ./tmp/
tmp-clean: true
tmp-first-clean-time: 2020-1-17 11:45:00
tmp-clean-period: 12960000
tmp-alive-duration: 12960000
如果不配置默认bucket,则需要在使用api时指定。存储时指定的bucket如果不存在,则会自动创建。
tmp-dir 为api中返回File类型的缓存目录,这个目录会按照FIFO规则定时清理。如果使用返回InputStream的api,则不会有缓存。
tmp-clean如果设置为false,则后续的tmp相关配置也不会生效。只有在使用getFile api时,才会产生缓存,若确定不使用这个,则可以关闭tmp-clean。
使用
兼容v1.0.0的所有用发,新增的示例如下:
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 {
@Autowired
FileStoreService fileStoreService;
@GetMapping("test2")
public void test2(HttpServletResponse response) throws IOException {
String bucketName = "demo-bucket";
// 创建bucket
boolean created = fileStoreService.createBucket(bucketName);
// 存储文件
String saved = fileStoreService.save(bucketName, new File("C:\asd.txt"), "a.txt");
// 删除文件
boolean deleted = fileStoreService.delete(bucketName, "a.txt");
// 获取文件(会产生本地缓存)
File file = fileStoreService.getFile(bucketName, "a.txt");
// 获取输入流
InputStream inputStream = fileStoreService.getStream(bucketName, "a.txt");
// 下载
response.addHeader("Content-Disposition","attachment;filename=a.txt");
ServletOutputStream os = response.getOutputStream();
fileStoreService.writeTo(bucketName, "a.txt", os);
}
}
change list
v1.0.0 常用功能的实现
- 实现使用minIO单bucket存储获取对象(文件)的功能
- 实现获取对象输入流、写入输出流等功能
v1.1.0 常用功能的实现
- 支持多个bucket,也兼容v1.0.0的配置默认bucket
- 可创建删除bucket
- 删除文件
有最新版1.2.0的更新说明吗?
功能上和1.1.0基本相同。1.2.0发现了一点问题,我正在发布1.2.1版本修改