Springboot+Minio的使用

Minio的使用

官网 https://docs.min.io/docs/java-client-api-reference.html

MinIO is a High Performance Object Storage released under Apache License v2.0.

一个高性能的对象存储软件。

用docker安装:

docker run -p 9000:9000 \
  --name minio1 \
  -v /mnt/data:/data \
  -d \
  -e "MINIO_ACCESS_KEY=java4ye" \
  -e "MINIO_SECRET_KEY=java123456" \
  minio/minio server /data

成功啦o( ̄▽ ̄)o

Springboot+Minio的使用_第1张图片

额 这里是加个 -d 参数让它在后台运行

Springboot+Minio的使用_第2张图片

跑起来的效果如下: 很赞

Springboot+Minio的使用_第3张图片

Springboot中使用:

pom文件中加入:

<dependency>
  <groupId>io.miniogroupId>
  <artifactId>minioartifactId>
  <version>7.1.0version>
dependency>

主要代码如下:

连接Minio:

MinioClient minioClient =
    MinioClient.builder()
        .endpoint("http://127.0.0.1:9000/")
        .credentials("accesskey", "secretkey")
        .build();

判断bucket存不存在:

minioClient.bucketExists(BucketExistsArgs.builder().bucket(buckerName).build());

创建bucket:

minioClient.makeBucket(MakeBucketArgs.builder().bucket(buckerName).build());

存储文件:

minioClient.putObject( PutObjectArgs.builder().bucket(buckerName).object(objectName).stream(
    stream, size, -1)
    .contentType(contextType)
    .build());

具体可以看看博主最近写的这个 Springboot-Minio 的项目,效果如下:

前端使用vue+element-ui,可同时上传多个文件,可以根据需要回显图片。注意这里博主设置了这些链接的有效期是两小时,有需要的可以根据需求去修改。

Springboot+Minio的使用_第4张图片

你可能感兴趣的:(Spring,java,vue,spring,boot)