当前位置: 代码迷 >> 综合 >> minio 使用
  详细解决方案

minio 使用

热度:75   发布时间:2023-11-24 17:38:54.0

直接上代码

import io.minio.MinioClient;
import io.minio.errors.*;
import org.testng.annotations.Test;
import org.xmlpull.v1.XmlPullParserException;import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;/*** @Title :* @className: TestMinio* @author: wangguangzhi* @time: 2021/10/12下午3:53* @version: 1.0**/
public class TestMinio {/** * @description: * @author: wangguangzhi* @methodName: test* @params: * @return: void* @time:  2021/10/13 上午11:18*/@Testpublic void test() {try {// 使用MinIO服务的URL,端口,Access key和Secret key创建一个MinioClient对象MinioClient minioClient = new MinioClient("http://10.33.217.106:9000/", "minioadmin", "minioadmin");// 检查存储桶是否已经存在boolean isExist = minioClient.bucketExists("wgzbd");if(isExist) {System.out.println("Bucket already exists.");} else {// 创建一个名为wgzbd的存储桶,用于存储照片的zip文件。minioClient.makeBucket("wgzbd");}// 使用putObject上传一个文件到存储桶中。minioClient.putObject("wgzbd","spring-boot-demo.tar.gz","/home/wangguangzhi/Software/IdeaProjects/spring-boot-demo.tar.gz",null);System.out.println("successfully uploaded");String url = minioClient.getObjectUrl("wgzbd", "spring-boot-demo.tar.gz");System.out.println(url);} catch(MinioException | NoSuchAlgorithmException | IOException | InvalidKeyException e) {System.out.println("Error occurred: " + e);}}
}

查看minio服务器是否接收到文件