From 015b4060011ed00262369d49fc36d420f2f040a4 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子Li <15040126243@163.com> Date: 星期五, 25 十月 2024 11:09:23 +0800 Subject: [PATCH] !591 发布 5.2.3 正式版 Merge pull request !591 from 疯狂的狮子Li/dev --- ruoyi-common/ruoyi-common-oss/src/main/java/org/dromara/common/oss/core/OssClient.java | 30 ++++++++++++++++++++---------- 1 files changed, 20 insertions(+), 10 deletions(-) diff --git a/ruoyi-common/ruoyi-common-oss/src/main/java/org/dromara/common/oss/core/OssClient.java b/ruoyi-common/ruoyi-common-oss/src/main/java/org/dromara/common/oss/core/OssClient.java index 5e300da..900536b 100644 --- a/ruoyi-common/ruoyi-common-oss/src/main/java/org/dromara/common/oss/core/OssClient.java +++ b/ruoyi-common/ruoyi-common-oss/src/main/java/org/dromara/common/oss/core/OssClient.java @@ -15,12 +15,12 @@ import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; import software.amazon.awssdk.core.ResponseInputStream; -import software.amazon.awssdk.core.async.AsyncRequestBody; import software.amazon.awssdk.core.async.AsyncResponseTransformer; import software.amazon.awssdk.core.async.BlockingInputStreamAsyncRequestBody; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.s3.S3AsyncClient; import software.amazon.awssdk.services.s3.S3Configuration; +import software.amazon.awssdk.services.s3.crt.S3CrtHttpConfiguration; import software.amazon.awssdk.services.s3.model.GetObjectResponse; import software.amazon.awssdk.services.s3.model.NoSuchBucketException; import software.amazon.awssdk.services.s3.model.S3Exception; @@ -83,8 +83,8 @@ StaticCredentialsProvider credentialsProvider = StaticCredentialsProvider.create( AwsBasicCredentials.create(properties.getAccessKey(), properties.getSecretKey())); - //MinIO 浣跨敤 HTTPS 闄愬埗浣跨敤鍩熷悕璁块棶锛岀珯鐐瑰~鍩熷悕銆傞渶瑕佸惎鐢ㄨ矾寰勬牱寮忚闂� - boolean isStyle = !StringUtils.containsAny(properties.getEndpoint(), OssConstant.CLOUD_SERVICE); + //浣跨敤瀵硅薄瀛樺偍鏈嶅姟鏃惰姹傛槑纭厤缃闂牱寮忥紙璺緞鏍峰紡鎴栬櫄鎷熸墭绠℃牱寮忥級銆傞渶瑕佸惎鐢ㄨ矾寰勬牱寮忚闂� + boolean isStyle = true; //鍒涘缓AWS鍩轰簬 CRT 鐨� S3 瀹㈡埛绔� this.client = S3AsyncClient.crtBuilder() @@ -95,6 +95,9 @@ .minimumPartSizeInBytes(10 * 1025 * 1024L) .checksumValidationEnabled(false) .forcePathStyle(isStyle) + .httpConfiguration(S3CrtHttpConfiguration.builder() + .connectionTimeout(Duration.ofSeconds(60)) // 璁剧疆杩炴帴瓒呮椂 + .build()) .build(); //AWS鍩轰簬 CRT 鐨� S3 AsyncClient 瀹炰緥鐢ㄤ綔 S3 浼犺緭绠$悊鍣ㄧ殑搴曞眰瀹㈡埛绔� @@ -178,7 +181,9 @@ .key(key) .contentMD5(StringUtils.isNotEmpty(md5Digest) ? md5Digest : null) .contentType(contentType) - .acl(getAccessPolicy().getObjectCannedACL()) + // 鐢ㄤ簬璁剧疆瀵硅薄鐨勮闂帶鍒跺垪琛紙ACL锛夈�備笉鍚屼簯鍘傚晢瀵笰CL鐨勬敮鎸佸拰瀹炵幇鏂瑰紡鏈夋墍涓嶅悓锛� + // 鍥犳鏍规嵁鍏蜂綋鐨勪簯鏈嶅姟鎻愪緵鍟嗭紝浣犲彲鑳介渶瑕佽繘琛屼笉鍚岀殑閰嶇疆锛堣嚜琛屽紑鍚紝闃块噷浜戞湁acl鏉冮檺閰嶇疆锛岃吘璁簯娌℃湁acl鏉冮檺閰嶇疆锛� + //.acl(getAccessPolicy().getObjectCannedACL()) .build()) .addTransferListener(LoggingTransferListener.create()) .source(filePath).build()); @@ -215,7 +220,10 @@ } try { // 鍒涘缓寮傛璇锋眰浣擄紙length濡傛灉涓虹┖浼氭姤閿欙級 - BlockingInputStreamAsyncRequestBody body = AsyncRequestBody.forBlockingInputStream(length); + BlockingInputStreamAsyncRequestBody body = BlockingInputStreamAsyncRequestBody.builder() + .contentLength(length) + .subscribeTimeout(Duration.ofSeconds(30)) + .build(); // 浣跨敤 transferManager 杩涜涓婁紶 Upload upload = transferManager.upload( @@ -224,7 +232,9 @@ y -> y.bucket(properties.getBucketName()) .key(key) .contentType(contentType) - .acl(getAccessPolicy().getObjectCannedACL()) + // 鐢ㄤ簬璁剧疆瀵硅薄鐨勮闂帶鍒跺垪琛紙ACL锛夈�備笉鍚屼簯鍘傚晢瀵笰CL鐨勬敮鎸佸拰瀹炵幇鏂瑰紡鏈夋墍涓嶅悓锛� + // 鍥犳鏍规嵁鍏蜂綋鐨勪簯鏈嶅姟鎻愪緵鍟嗭紝浣犲彲鑳介渶瑕佽繘琛屼笉鍚岀殑閰嶇疆锛堣嚜琛屽紑鍚紝闃块噷浜戞湁acl鏉冮檺閰嶇疆锛岃吘璁簯娌℃湁acl鏉冮檺閰嶇疆锛� + //.acl(getAccessPolicy().getObjectCannedACL()) .build()) .build()); @@ -340,8 +350,8 @@ * @return UploadResult 鍖呭惈涓婁紶鍚庣殑鏂囦欢淇℃伅 * @throws OssException 濡傛灉涓婁紶澶辫触锛屾姏鍑鸿嚜瀹氫箟寮傚父 */ - public UploadResult uploadSuffix(byte[] data, String suffix) { - return upload(new ByteArrayInputStream(data), getPath(properties.getPrefix(), suffix), Long.valueOf(data.length), FileUtils.getMimeType(suffix)); + public UploadResult uploadSuffix(byte[] data, String suffix, String contentType) { + return upload(new ByteArrayInputStream(data), getPath(properties.getPrefix(), suffix), Long.valueOf(data.length), contentType); } /** @@ -353,8 +363,8 @@ * @return UploadResult 鍖呭惈涓婁紶鍚庣殑鏂囦欢淇℃伅 * @throws OssException 濡傛灉涓婁紶澶辫触锛屾姏鍑鸿嚜瀹氫箟寮傚父 */ - public UploadResult uploadSuffix(InputStream inputStream, String suffix, Long length) { - return upload(inputStream, getPath(properties.getPrefix(), suffix), length, FileUtils.getMimeType(suffix)); + public UploadResult uploadSuffix(InputStream inputStream, String suffix, Long length, String contentType) { + return upload(inputStream, getPath(properties.getPrefix(), suffix), length, contentType); } /** -- Gitblit v1.9.3