Commit 82f8d95e authored by duanledexianxianxian's avatar duanledexianxianxian 😁

sync

parent eb244b41
......@@ -6,13 +6,13 @@
<groupId>com.duanledexianxianxian.demo</groupId>
<artifactId>demo-parent</artifactId>
<packaging>pom</packaging>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<version>2.4.3</version>
</parent>
<dependencies>
......@@ -42,6 +42,18 @@
<artifactId>guava</artifactId>
<version>23.0</version>
</dependency>
<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
<version>8.1.0</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<!-- <version>1.3.70</version>-->
</dependency>
</dependencies>
<properties>
......@@ -50,11 +62,35 @@
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>
src/main/java
</directory>
<includes>
<include>**/*.*</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
......
package com.duanledexianxianxian.demo;
import io.minio.BucketExistsArgs;
import io.minio.MakeBucketArgs;
import io.minio.MinioClient;
import io.minio.PutObjectArgs;
import io.minio.errors.MinioException;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
/**
* @author duanledexianxianxian
* @date 2021/3/2 1:25
* @since 1.0.0
*/
public class MinIOClientDemo {
public static void main(String[] args) {
try {
// 使用MinIO服务的URL,端口,Access key和Secret key创建一个MinioClient对象
MinioClient minioClient =
MinioClient.builder()
.endpoint("http://platform.kuopu.net:50001")
.credentials("minio", "minio123")
.build();
// 检查存储桶是否已经存在
boolean isExist = minioClient.bucketExists(BucketExistsArgs.builder().bucket("kim-dev").build());
if (isExist) {
System.out.println("Bucket already exists.");
} else {
// 创建一个名为kim-dev的存储桶,用于存储照片的zip文件。
minioClient.makeBucket(MakeBucketArgs.builder().bucket("kim-dev").build());
}
// 使用putObject上传一个文件到存储桶中。
minioClient.putObject(PutObjectArgs.builder().bucket("kim-dev").object("data2.txt").stream(
MinIOClientDemo.class.getClassLoader().getResourceAsStream("./files/data2.txt"), -1, 1024*5*1024)
.contentType("video/mp4")
.build());
System.out.println("this.getClass().getClassLoader().getResource(\"/files/data2.txt\") is successfully uploaded as asiaphotos.zip to `asiatrip` bucket.");
} catch (MinioException e) {
System.out.println("Error occurred: " + e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
}
//// 当前类的目录
//System.out.println(MinIOClientDemo.class.getResource(""));
//// 当前项目的目录
//System.out.println(MinIOClientDemo.class.getResource("/"));
//// 当前类的目录下的文件
//System.out.println(MinIOClientDemo.class.getResource("data1.txt"));
//// 绝对路径不存在
//System.out.println(MinIOClientDemo.class.getResource("/data1.txt"));
//
//// 当前项目的目录
//System.out.println(MinIOClientDemo.class.getClassLoader().getResource(""));
//System.out.println(MinIOClientDemo.class.getClassLoader().getResource("/"));
//System.out.println(MinIOClientDemo.class.getClassLoader().getResource("data1.txt"));
//System.out.println(MinIOClientDemo.class.getClassLoader().getResource("/data1.txt"));
//// 当前项目的目录
//System.out.println(MinIOClientDemo.class.getClassLoader().getResource("application.yml"));
//// 当前项目的目录
//System.out.println(MinIOClientDemo.class.getClassLoader().getResource("./files/data2.txt"));
}
}
hello world
\ No newline at end of file
hello world
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment