| 
					
				 | 
			
			
				@@ -0,0 +1,66 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+package com.ozs.common.utils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import io.minio.MinioClient; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import io.minio.PutObjectArgs; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import io.swagger.annotations.ApiImplicitParam; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import lombok.extern.slf4j.Slf4j; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.apache.poi.ss.usermodel.DateUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.beans.factory.annotation.Value; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+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; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+@Slf4j 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+@Component 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+public class MinioUtils { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Value("${minio.endpoint}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private String endpoint; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Value("${minio.accessKey}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private String accessKey; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Value("${minio.secretKey}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private String secretKey; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Value("${minio.bucketName}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private String bucketName; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 上传 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param imgInputStream 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param objectName 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @throws Exception 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void minIoClientUpload(InputStream imgInputStream, String objectName) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //创建头部信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Map<String, String> headers = new HashMap<>(10); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //添加自定义内容类型 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        headers.put("Content-Type", "application/octet-stream"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //添加存储类 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        headers.put("X-Amz-Storage-Class", "REDUCED_REDUNDANCY"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //添加自定义/用户元数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        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) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .object(objectName) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .stream(imgInputStream, imgInputStream.available(), -1) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .userMetadata(userMetadata) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .build()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        imgInputStream.close(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 |