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