diff --git a/sky-common/pom.xml b/sky-common/pom.xml
index 192675c..087ec5c 100644
--- a/sky-common/pom.xml
+++ b/sky-common/pom.xml
@@ -56,5 +56,16 @@
com.github.wechatpay-apiv3
wechatpay-apache-httpclient
+
+
+ io.minio
+ minio
+
+
+ com.sky
+ sky-server
+ 1.0-SNAPSHOT
+ compile
+
\ No newline at end of file
diff --git a/sky-common/src/main/java/com/sky/common/utils/MinioUtils.java b/sky-common/src/main/java/com/sky/common/utils/MinioUtils.java
new file mode 100644
index 0000000..de9b09c
--- /dev/null
+++ b/sky-common/src/main/java/com/sky/common/utils/MinioUtils.java
@@ -0,0 +1,112 @@
+package com.sky.common.utils;
+
+
+import com.sky.config.MinioConfig;
+import io.minio.*;
+import lombok.extern.slf4j.Slf4j;
+
+import javax.annotation.Resource;
+import java.io.InputStream;
+
+@Slf4j
+public class MinioUtils {
+ @Resource
+ private MinioClient minioClient;
+
+ @Resource
+ private MinioConfig config;
+
+ /**
+ * 判断桶是否存在
+ *
+ * @param bucketName String
+ * @return found
+ */
+ public boolean bucketExists(String bucketName) {
+ boolean found = false;
+ try {
+ found = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return found;
+ }
+
+ /**
+ * 如果桶不存在就新建
+ *
+ * @param bucketName String
+ */
+ public void bucketCreate(String bucketName) {
+ boolean exists = bucketExists(bucketName);
+ if (!exists) {
+ try {
+ minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ /**
+ * 上传文件
+ *
+ * @param fileName 文件名
+ * @param inputStream 输入流
+ * @param size 文件大小
+ */
+ public String uploadFile(String bucketName, String fileName, InputStream inputStream, Long size) {
+ try {
+ minioClient.putObject(PutObjectArgs.builder()
+ .bucket(bucketName)
+ .object(fileName)
+ .stream(inputStream, size, -1)
+ .build());
+ return config.getEndpointUrl() + "/" + bucketName + "/" + fileName;
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ /**
+ * 上传文件
+ *
+ * @param fileName 文件名
+ * @param inputStream 输入流
+ * @param size 文件大小
+ * @param contentType 文件类型
+ */
+ public String uploadFile(String bucketName, String fileName, InputStream inputStream, Long size, String contentType) {
+ try {
+ minioClient.putObject(PutObjectArgs.builder()
+ .bucket(bucketName)
+ .object(fileName)
+ .stream(inputStream, size, -1)
+ .contentType(contentType)
+ .build());
+ return config.getEndpointUrl() + "/" + bucketName + "/" + fileName;
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ /**
+ * 获取文件
+ *
+ * @param bucketName 桶名称
+ * @param fileName 对象名称
+ */
+ public InputStream getFile(String bucketName, String fileName) {
+ try {
+ return minioClient.getObject(GetObjectArgs.builder()
+ .bucket(bucketName)
+ .object(fileName)
+ .build());
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+}
\ No newline at end of file
diff --git a/sky-server/src/main/java/com/sky/config/MinioConfig.java b/sky-server/src/main/java/com/sky/config/MinioConfig.java
new file mode 100644
index 0000000..ccd17c0
--- /dev/null
+++ b/sky-server/src/main/java/com/sky/config/MinioConfig.java
@@ -0,0 +1,22 @@
+package com.sky.config;
+
+import io.minio.MinioClient;
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Data
+@Configuration
+@ConfigurationProperties(prefix = "sky.minio")
+public class MinioConfig {
+ private String endpointUrl;
+ private String accessKey;
+ private String secretKey;
+ private String bucketName;
+
+ @Bean
+ public MinioClient minioClient() {
+ return MinioClient.builder().endpoint(endpointUrl).credentials(accessKey, secretKey).build();
+ }
+}