当前位置:网站首页>对象存储Minio使用教程
对象存储Minio使用教程
2022-06-11 03:13:00 【菜鸟小窝】
Minio使用教程
一、概述
1、官方文档
中文文档:http://docs.minio.org.cn/docs/master/java-client-api-reference
英文文档:https://docs.min.io/docs/java-client-api-reference.html
注意:中文文档更新较慢,会和最新版本的客户端API不兼容。如果使用最新的客户端API,最好看英文文档,否则会有很多坑。
2、参考文档
Minio入门系列(Minio8.x)
https://blog.csdn.net/qq_43437874/category_10562215.html
主要基于2021版本的minio来介绍的,使用的java客户端版本为 8.3.1。
SpringBoot集成Minio7.x文件存储服务器(包含服务器安装搭建)
https://blog.csdn.net/weixin_44248000/article/details/124118290
二、Java案例(7.x)
1、引入pom.xml
<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
<version>7.0.2</version>
</dependency>
2、java代码
package work.vcloud.exam.controller.test.minio;
import io.minio.MinioClient;
import io.minio.PutObjectOptions;
import io.minio.Result;
import io.minio.messages.Bucket;
import io.minio.messages.Item;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.List;
public class MinioDemo {
public static void main(String[] args) {
try {
String accessKey = "Minio";
String secretKey = "Test123456";
//String endpoint = "http://192.168.1.115:9000";
String endpoint = "http://centos115:9000";
String bucketName = "resource";
// 使用MinIO服务的URL,端口,Access key和Secret key创建一个MinioClient对象
MinioClient minioClient = new MinioClient(endpoint, accessKey, secretKey);
// 检查存储桶是否已经存在
String test_bucketName = "asiatrip";
boolean isExist = minioClient.bucketExists(test_bucketName);
System.out.println(isExist);
if (!isExist) {
minioClient.makeBucket(test_bucketName);
}
// 移除存储桶
minioClient.removeBucket(test_bucketName);
// 遍历所有桶
List<Bucket> buckets = minioClient.listBuckets();
if (buckets != null && !buckets.isEmpty()) {
buckets.forEach(bucket -> {
System.out.println(bucket.name());
});
}
String objectName = "Downloads/movie.mp4";
// 使用putObject上传一个文件到存储桶中。
File file = new File("C:\\Users\\jiuhui-4\\Downloads\\movie.mp4");
InputStream is = new FileInputStream(file);
// 使用putObject上传一个本地文件到存储桶中。
minioClient.putObject(bucketName, objectName, is, new PutObjectOptions(is.available(), -1));
is.close();
// 获取对象url
String file_url = minioClient.getObjectUrl(bucketName, "movie.mp4");
System.out.println(file_url);
// 删除对象
minioClient.removeObject(bucketName, "movie.mp4");
//if (1 == 1) return;
// 列出'my-bucketname'里的对象
Iterable<Result<Item>> myObjects = minioClient.listObjects(bucketName);
for (Result<Item> result : myObjects) {
Item item = result.get();
System.out.println(item.lastModified() + ", " + item.size() + ", " + item.objectName());
}
// 分享连接
String url = minioClient.presignedGetObject(bucketName, objectName, 60 * 60 * 24);
System.out.println(url);
} catch (Exception e) {
e.printStackTrace();
}
}
}
3、更多案例
更多使用案例可以参考下面的文档。因为官网随时可能更新,所以我吧7.x版本的文档保存下来了。
[Minio Java 文档(7.X)](Minio Java 文档(7.X))
边栏推荐
- 023 MySQL索引优化口诀-索引失效的常见情况
- [safety science popularization] have you been accepted by social workers today?
- Array full permutation
- 通过程序启动QQ,实现自动登录.
- B / Qurt Utilisateur Guide (19)
- Demand and Prospect of 3D GIS Industry
- A simple understanding of C language array
- Artalk | how to build a domestic hyperfusion evolutionary base with minimum investment?
- postgresql源码学习(二十)—— 故障恢复①-事务日志格式
- 计算机视觉(AI)面试大全
猜你喜欢

The solution of invalid @data annotation in idea2018

计算机视觉(AI)面试大全

Artalk | how to build a domestic hyperfusion evolutionary base with minimum investment?

How to ensure reliable delivery of messages?

Configuring the command line compiled environment -msvc

Hough transform of image

B_QuRT_User_Guide(17)

Delete the watermark of the picture uploaded by CSDN

2022年6月中国数据库排行榜:TiDB卷土重来摘桂冠,达梦蛰伏五月夺探花

Chapter VII introduction to common protocols (1)
随机推荐
R分析可视化实用数据(航班_教育_餐厅_租户_变迁_寿命_安全)
Operations on annotation and reflection
Demand and Prospect of 3D GIS Industry
Artalk | how to build a domestic hyperfusion evolutionary base with minimum investment?
C语言指针
【安全科普】今天你被社工了吗?
Log4j use
Three ways of reflection
HikariPool-1 - Shutdown initiated... HikariPool-1 - Shutdown completed.
Cypress 88359 WL command enable hotspot
计算机视觉(AI)面试大全
Chapter VII introduction to common protocols (1)
名不副实的雅迪高端品牌VFLY,为何“不高端”?
What is the difference between a database unique index and a common index?
A simple understanding of C language array
Difference between idea open and import project
Troubleshooting of single chip microcomputer communication data delay
In June, 2022, China Database ranking: tidb made a comeback to win the crown, and Dameng was dormant and won the flowers in May
Computer vision (AI) interview
ASLR