From 17f0c20242c6ee3d35b9ee8f677d747ed012423c Mon Sep 17 00:00:00 2001
From: 疯狂的狮子li <15040126243@163.com>
Date: 星期五, 02 九月 2022 16:30:20 +0800
Subject: [PATCH] remove 移除maven docker插件 过于老旧功能缺陷大 使用idea自带的docker插件替代

---
 ruoyi-oss/src/main/java/com/ruoyi/oss/core/OssClient.java |   35 +++++++++++++++++++++++++----------
 1 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/ruoyi-oss/src/main/java/com/ruoyi/oss/core/OssClient.java b/ruoyi-oss/src/main/java/com/ruoyi/oss/core/OssClient.java
index 03c8396..15833d3 100644
--- a/ruoyi-oss/src/main/java/com/ruoyi/oss/core/OssClient.java
+++ b/ruoyi-oss/src/main/java/com/ruoyi/oss/core/OssClient.java
@@ -10,10 +10,8 @@
 import com.amazonaws.client.builder.AwsClientBuilder;
 import com.amazonaws.services.s3.AmazonS3;
 import com.amazonaws.services.s3.AmazonS3Client;
-import com.amazonaws.services.s3.model.CannedAccessControlList;
-import com.amazonaws.services.s3.model.CreateBucketRequest;
-import com.amazonaws.services.s3.model.ObjectMetadata;
-import com.amazonaws.services.s3.model.PutObjectRequest;
+import com.amazonaws.services.s3.AmazonS3ClientBuilder;
+import com.amazonaws.services.s3.model.*;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.oss.constant.OssConstant;
@@ -54,12 +52,16 @@
             } else {
                 clientConfig.setProtocol(Protocol.HTTP);
             }
-            this.client = AmazonS3Client.builder()
+            AmazonS3ClientBuilder build = AmazonS3Client.builder()
                 .withEndpointConfiguration(endpointConfig)
                 .withClientConfiguration(clientConfig)
                 .withCredentials(credentialsProvider)
-                .disableChunkedEncoding()
-                .build();
+                .disableChunkedEncoding();
+            if (!StringUtils.containsAny(properties.getEndpoint(), OssConstant.CLOUD_SERVICE)){
+                // minio 浣跨敤https闄愬埗浣跨敤鍩熷悕璁块棶 闇�瑕佹閰嶇疆 绔欑偣濉煙鍚�
+                build.enablePathStyleAccess();
+            }
+            this.client = build.build();
 
             createBucket();
         } catch (Exception e) {
@@ -94,7 +96,10 @@
             ObjectMetadata metadata = new ObjectMetadata();
             metadata.setContentType(contentType);
             metadata.setContentLength(inputStream.available());
-            client.putObject(new PutObjectRequest(properties.getBucketName(), path, inputStream, metadata));
+            PutObjectRequest putObjectRequest = new PutObjectRequest(properties.getBucketName(), path, inputStream, metadata);
+            // 璁剧疆涓婁紶瀵硅薄鐨� Acl 涓哄叕鍏辫
+            putObjectRequest.setCannedAcl(CannedAccessControlList.PublicRead);
+            client.putObject(putObjectRequest);
         } catch (Exception e) {
             throw new OssException("涓婁紶鏂囦欢澶辫触锛岃妫�鏌ラ厤缃俊鎭�:[" + e.getMessage() + "]");
         }
@@ -118,6 +123,16 @@
         return upload(inputStream, getPath(properties.getPrefix(), suffix), contentType);
     }
 
+    /**
+     * 鑾峰彇鏂囦欢鍏冩暟鎹�
+     *
+     * @param path 瀹屾暣鏂囦欢璺緞
+     */
+    public ObjectMetadata getObjectMetadata(String path) {
+        S3Object object = client.getObject(properties.getBucketName(), path);
+        return object.getObjectMetadata();
+    }
+
     public String getUrl() {
         String domain = properties.getDomain();
         String endpoint = properties.getEndpoint();
@@ -125,13 +140,13 @@
         // 浜戞湇鍔″晢鐩存帴杩斿洖
         if (StringUtils.containsAny(endpoint, OssConstant.CLOUD_SERVICE)){
             if (StringUtils.isNotBlank(domain)) {
-                return domain;
+                return header + domain;
             }
             return header + properties.getBucketName() + "." + endpoint;
         }
         // minio 鍗曠嫭澶勭悊
         if (StringUtils.isNotBlank(domain)) {
-            return domain + "/" + properties.getBucketName();
+            return header + domain + "/" + properties.getBucketName();
         }
         return header + endpoint + "/" + properties.getBucketName();
     }

--
Gitblit v1.9.3