From f1208474f771a1c233d7425c8ed13fbaa0d521ac Mon Sep 17 00:00:00 2001 From: baoshiwei <baoshiwei@shlanbao.cn> Date: 星期三, 12 三月 2025 09:35:13 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/5.X' into 5.X --- ruoyi-common/ruoyi-common-oss/src/main/java/org/dromara/common/oss/core/OssClient.java | 17 +++++++++++------ 1 files changed, 11 insertions(+), 6 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 1261b47..e3b20dd 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 @@ -32,6 +32,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.time.Duration; +import java.util.function.Consumer; /** * S3 瀛樺偍鍗忚 鎵�鏈夊吋瀹筍3鍗忚鐨勪簯鍘傚晢鍧囨敮鎸� @@ -239,10 +240,11 @@ * * @param key 鏂囦欢鍦� Amazon S3 涓殑瀵硅薄閿� * @param out 杈撳嚭娴� + * @param consumer 鑷畾涔夊鐞嗛�昏緫 * @return 杈撳嚭娴佷腑鍐欏叆鐨勫瓧鑺傛暟锛堥暱搴︼級 * @throws OssException 濡傛灉涓嬭浇澶辫触锛屾姏鍑鸿嚜瀹氫箟寮傚父 */ - public long download(String key, OutputStream out) { + public void download(String key, OutputStream out, Consumer<Long> consumer) { try { // 鏋勫缓涓嬭浇璇锋眰 DownloadRequest<ResponseInputStream<GetObjectResponse>> downloadRequest = DownloadRequest.builder() @@ -258,7 +260,10 @@ Download<ResponseInputStream<GetObjectResponse>> responseFuture = transferManager.download(downloadRequest); // 杈撳嚭鍒版祦涓� try (ResponseInputStream<GetObjectResponse> responseStream = responseFuture.completionFuture().join().result()) { // auto-closeable stream - return responseStream.transferTo(out); // 闃诲璋冪敤绾跨▼ blocks the calling thread + if (consumer != null) { + consumer.accept(responseStream.response().contentLength()); + } + responseStream.transferTo(out); // 闃诲璋冪敤绾跨▼ blocks the calling thread } } catch (Exception e) { throw new OssException("鏂囦欢涓嬭浇澶辫触锛岄敊璇俊鎭�:[" + e.getMessage() + "]"); @@ -284,13 +289,13 @@ /** * 鑾峰彇绉佹湁URL閾炬帴 * - * @param objectKey 瀵硅薄KEY - * @param second 鎺堟潈鏃堕棿 + * @param objectKey 瀵硅薄KEY + * @param expiredTime 閾炬帴鎺堟潈鍒版湡鏃堕棿 */ - public String getPrivateUrl(String objectKey, Integer second) { + public String getPrivateUrl(String objectKey, Duration expiredTime) { // 浣跨敤 AWS S3 棰勭鍚� URL 鐨勭敓鎴愬櫒 鑾峰彇瀵硅薄鐨勯绛惧悕 URL URL url = presigner.presignGetObject( - x -> x.signatureDuration(Duration.ofSeconds(second)) + x -> x.signatureDuration(expiredTime) .getObjectRequest( y -> y.bucket(properties.getBucketName()) .key(objectKey) -- Gitblit v1.9.3