最近公司想把本地储存这块obs换成minio,查了各个文档、包括网上的资料,都没有提到过
首先要排除掉okhttp
<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
<version>8.3.3</version>
<exclusions>
<exclusion>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
</exclusion>
</exclusions>
</dependency>
然后加入自己的okhttp
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.9.0</version>
</dependency>
重点来了,需要加上okio,必须对应的版本
<dependency>
<groupId>com.squareup.okio</groupId>
<artifactId>okio</artifactId>
<version>2.8.0</version>
</dependency>
try {
// Create a minioClient with the MinIO server playground, its access key and secret key. http://192.168.6.248:35684 http://192.168.6.248:9000
MinioClient minioClient =
MinioClient.builder()
.endpoint("http://192.168.6.248:9000")//服务器地址
.credentials("leon", "12345678")//用户名、密码
.build();
// Make 'asiatrip' bucket if not exist.
boolean found =
minioClient.bucketExists(BucketExistsArgs.builder().bucket("test").build());
if (!found) {
// Make a new bucket called 'asiatrip'.
minioClient.makeBucket(MakeBucketArgs.builder().bucket("test").build());
} else {
System.out.println("Bucket 'test' already exists.");
}
// Upload '/home/user/Photos/asiaphotos.zip' as object name 'asiaphotos-2015.zip' to bucket
// 'asiatrip'.
minioClient.uploadObject(
UploadObjectArgs.builder()
.bucket("test")//桶名称
.object("111")
.filename("D:\\111.jpg")
.build());
} catch (MinioException e) {
System.out.println("Error occurred: " + e);
System.out.println("HTTP trace: " + e.httpTrace());
}
上传成功