MINIO使用

1.作用

官网地址https://docs.min.io/

文件存储。文件对象的上传、下载和删除!

2.使用依赖

<dependency>
    <groupId>io.minio</groupId>
    <artifactId>minio</artifactId>
    <version>8.4.3</version>
</dependency>

3. 构建client 桶

MinioClient minioClient =
                    MinioClient.builder()
                            .endpoint("http://127.0.0.1:9000")
                            .credentials("minioadmin", "minioadmin")
                            .build();	
// 桶:存放多个文件数据的存储空间
            boolean found =
                    minioClient.bucketExists(BucketExistsArgs.builder().bucket("crm").build());
            if (!found) {
                // Make a new bucket called 'asiatrip'.
                minioClient.makeBucket(MakeBucketArgs.builder().bucket("crm").build());
            } else {
                System.out.println("Bucket 'crm' already exists.");
            }

3.1.文件上传

FileInputStream inputStream = new FileInputStream("E:\\42eb3c72-f80e-4b5e-9390-7861288e922f.jpg");
            minioClient.putObject(
                    PutObjectArgs.builder()
                            .bucket("crm")
                            .object("2022/07/19/demo02.jpg")
                            .stream(inputStream,inputStream.available(),-1)
                            .build()
            );

4.文件下载

InputStream  inputStream = minioClient.getObject(GetObjectArgs.builder().bucket("crm").object("2022/07/19/demo02.jpg").build());
            FileOutputStream outputStream = new FileOutputStream("E:/xxx02.jpg");
            IOUtils.copy(inputStream,outputStream);
            System.out.println("x传成功");

5.文件删除

posted @ 2022-07-19 22:17  你会很厉害的  阅读(666)  评论(0编辑  收藏  举报
//雪花飘落效果