对象存储服务MinIO

 

构建MinIO起步依赖

<dependencies>

<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
<version>7.1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
</dependencies>

 

效果:

只要添加common的依赖,准备配置文件,就可以直接使用MinIo的工具类,操作MinIon相当于MYbatis的起步依赖

一:准备MinIo的配置加载   配置类加载配置文件

 

二:准备MinIo工具类,进行MinIo的操作   上传    下载.....

 

三:准备统一的自动装配类    进行工具类的创建

引导类:

@SpringBootApplication
public class MinIOApplication {

public static void main(String[] args) {
SpringApplication.run(MinIOApplication.class,args);
}
}

创建测试类,上传html文件:

public class MinIOTest {

public static void main(String[] args) {

FileInputStream fileInputStream = null;
try {

fileInputStream = new FileInputStream("C:\\5_code\\list.html");;

//1.创建minio链接客户端
MinioClient minioClient = MinioClient.builder()
.credentials("minio", "minio123")
.endpoint("http://192.168.200.128:9000").build();
//2.上传
PutObjectArgs putObjectArgs = PutObjectArgs.builder()
.object("list.html")//文件名
.contentType("text/html")//文件类型
.bucket("leadnews")//桶名词 与minio创建的名词一致
.stream(fileInputStream, fileInputStream.available(), -1) //文件流
.build();
minioClient.putObject(putObjectArgs);

System.out.println("http://192.168.200.128:9000/leadnews/list.html");

} catch (Exception ex) {
ex.printStackTrace();
}
}

}

 

posted @ 2022-05-17 21:07  再无桃花日  阅读(82)  评论(0)    收藏  举报