1.下载安装
https://dl.min.io/server/minio/release/windows-amd64/minio.exe
2.启动
powershell下
- C:\minio 文件存储目录
.\minio.exe server C:\minio --console-address :9090
3.访问
http://127.0.0.1:9090
账号密码都是minioadmin
4.Java上传下载
- 依赖
<!--MinIO-->
<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
<version>8.5.6</version>
</dependency>
- 要先在控制台新建一个存储桶
public void test1() throws Exception {
try {
// 创建MinioClient对象
MinioClient minioClient = MinioClient.builder()
.endpoint("http://127.0.0.1:9000")
.credentials("minioadmin", "minioadmin")
.build();
// 定义存储桶和对象名称
String bucketName = "test";
String objectName = "test.png";
String filePath = "C:\\Users\\lwx20\\Desktop\\test.png";
// 上传对象到存储桶
minioClient.uploadObject(
UploadObjectArgs.builder()
.bucket(bucketName)
.object(objectName)
.filename(filePath)
.build()
);
System.out.println("Uploaded object to bucket.");
// 下载对象
try (InputStream stream = minioClient.getObject(
GetObjectArgs.builder()
.bucket(bucketName)
.object(objectName)
.build()
)) {
Files.copy(stream, Path.of("C:\\Users\\lwx20\\Desktop\\downloaded-" + objectName), StandardCopyOption.REPLACE_EXISTING);
}
System.out.println("Downloaded object from bucket.");
// 删除对象
minioClient.removeObject(
RemoveObjectArgs.builder()
.bucket(bucketName)
.object(objectName)
.build()
);
System.out.println("Deleted object from bucket.");
} catch (MinioException e) {
System.out.println("Error occurred: " + e);
}
}
标签:Minio,objectName,object,bucket,bucketName,println,Winows,安装,minio
From: https://www.cnblogs.com/lwx11111/p/17775997.html