Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
springboot-demo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Leona
W
web
backend
springboot-demo
Commits
82f8d95e
Commit
82f8d95e
authored
Mar 03, 2021
by
duanledexianxianxian
😁
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sync
parent
eb244b41
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
112 additions
and
2 deletions
+112
-2
pom.xml
pom.xml
+38
-2
src/main/java/com/duanledexianxianxian/demo/MinIOClientDemo.java
...n/java/com/duanledexianxianxian/demo/MinIOClientDemo.java
+72
-0
src/main/java/com/duanledexianxianxian/demo/data1.txt
src/main/java/com/duanledexianxianxian/demo/data1.txt
+1
-0
src/main/resources/files/data2.txt
src/main/resources/files/data2.txt
+1
-0
No files found.
pom.xml
View file @
82f8d95e
...
@@ -6,13 +6,13 @@
...
@@ -6,13 +6,13 @@
<groupId>
com.duanledexianxianxian.demo
</groupId>
<groupId>
com.duanledexianxianxian.demo
</groupId>
<artifactId>
demo-parent
</artifactId>
<artifactId>
demo-parent
</artifactId>
<packaging>
pom
</packaging>
<packaging>
jar
</packaging>
<version>
1.0-SNAPSHOT
</version>
<version>
1.0-SNAPSHOT
</version>
<parent>
<parent>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-parent
</artifactId>
<artifactId>
spring-boot-starter-parent
</artifactId>
<version>
2.
1.6.RELEASE
</version>
<version>
2.
4.3
</version>
</parent>
</parent>
<dependencies>
<dependencies>
...
@@ -42,6 +42,18 @@
...
@@ -42,6 +42,18 @@
<artifactId>
guava
</artifactId>
<artifactId>
guava
</artifactId>
<version>
23.0
</version>
<version>
23.0
</version>
</dependency>
</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>
</dependencies>
<properties>
<properties>
...
@@ -50,11 +62,35 @@
...
@@ -50,11 +62,35 @@
<build>
<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>
<plugins>
<plugin>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
</plugin>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-resources-plugin
</artifactId>
<configuration>
<encoding>
UTF-8
</encoding>
</configuration>
</plugin>
</plugins>
</plugins>
</build>
</build>
...
...
src/main/java/com/duanledexianxianxian/demo/MinIOClientDemo.java
0 → 100644
View file @
82f8d95e
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"));
}
}
src/main/java/com/duanledexianxianxian/demo/data1.txt
0 → 100644
View file @
82f8d95e
hello world
\ No newline at end of file
src/main/resources/files/data2.txt
0 → 100644
View file @
82f8d95e
hello world
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment