From e104f0cce53fe27be1520cfc6469e16feeced927 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子li <15040126243@163.com> Date: 星期一, 22 八月 2022 18:42:33 +0800 Subject: [PATCH] fix 修复 minio配置https遇到的问题 --- ruoyi-oss/src/main/java/com/ruoyi/oss/core/OssClient.java | 26 +++++++++++++++++++------- 1 files changed, 19 insertions(+), 7 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..f0776dc 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,7 @@ 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.model.*; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.oss.constant.OssConstant; @@ -59,6 +56,8 @@ .withClientConfiguration(clientConfig) .withCredentials(credentialsProvider) .disableChunkedEncoding() + // https闄愬埗浣跨敤鍩熷悕璁块棶 闇�瑕佹閰嶇疆 绔欑偣濉煙鍚� + .enablePathStyleAccess() .build(); createBucket(); @@ -94,7 +93,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 +120,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 +137,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