Bläddra i källkod

添加机车kingbase

hexiao 2 år sedan
förälder
incheckning
de9d61aa96
1 ändrade filer med 26 tillägg och 9 borttagningar
  1. 26 9
      base-common/src/main/java/com/ozs/common/utils/MinioUtils.java

+ 26 - 9
base-common/src/main/java/com/ozs/common/utils/MinioUtils.java

@@ -8,10 +8,13 @@ import io.swagger.annotations.ApiImplicitParam;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
 import org.springframework.stereotype.Component;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.multipart.MultipartFile;
+
+import javax.annotation.PostConstruct;
 import java.io.InputStream;
 import java.util.HashMap;
 import java.util.Map;
@@ -31,11 +34,20 @@ public class MinioUtils {
 
     @Value(value = "${minio.bucketName}")
     private String bucketName;
-    
-    
+
+    private MinioClient minioClient;
+
+    @PostConstruct
+    public void create() {
+        this.minioClient = MinioClient.builder()
+                .endpoint(endpoint)
+                .credentials(accessKey, secretKey)
+                .build();
+    }
 
     /**
      * 上传
+     *
      * @param imgInputStream
      * @param objectName
      * @throws Exception
@@ -51,13 +63,6 @@ public class MinioUtils {
         Map<String, String> userMetadata = new HashMap<>(10);
         userMetadata.put("My-Project", "Project One");
 
-
-        MinioClient minioClient =
-                MinioClient.builder()
-                        .endpoint(endpoint)
-                        .credentials(accessKey, secretKey)
-                        .build();
-
         minioClient.putObject(
                 PutObjectArgs.builder()
                         .bucket(bucketName)
@@ -68,4 +73,16 @@ public class MinioUtils {
         imgInputStream.close();
 
     }
+
+    /**
+     * 图片上传
+     *
+     * @param imgInputStream
+     * @throws Exception
+     */
+    public void minIoClientUpload(InputStream imgInputStream) throws Exception {
+        minIoClientUpload(imgInputStream, bucketName);
+    }
+
+
 }