From 13e60a60488e71b28bb947bd15acb6de01366a7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Mon, 15 Jan 2024 09:36:55 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E4=BC=98=E5=8C=96=20oss=20=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E4=BD=BF=E7=94=A8=E4=B8=B4=E6=97=B6=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E9=81=BF=E5=85=8D=E7=BA=BF=E7=A8=8B=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dromara/common/oss/core/OssClient.java | 20 +++---------------- 1 file changed, 3 insertions(+), 17 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 6c402dc39..eb1656c06 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 @@ -34,7 +34,6 @@ import java.net.URI; import java.net.URL; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.time.Duration; /** @@ -242,16 +241,13 @@ public class OssClient { * @throws OssException 如果下载失败,抛出自定义异常 */ public Path fileDownload(String path) { - // 从路径中移除 URL 前缀 - String url = removeBaseUrl(path); - - // 构建临时文件路径 文件名必须是唯一不存在的,路径必须是存在的 - Path tempFilePath = Paths.get(extractFileName(url)); + // 构建临时文件 + Path tempFilePath = FileUtils.createTempFile().toPath(); // 使用 S3TransferManager 下载文件 FileDownload downloadFile = transferManager.downloadFile( x -> x.getObjectRequest( y -> y.bucket(properties.getBucketName()) - .key(url) + .key(removeBaseUrl(path)) .build()) .addTransferListener(LoggingTransferListener.create()) .destination(tempFilePath) @@ -451,16 +447,6 @@ public class OssClient { return path.replace(getUrl() + StringUtils.SLASH, ""); } - /** - * 从文件路径中提取文件名 - * - * @param path 文件路径 - * @return 提取的文件名或默认文件名 - */ - public String extractFileName(String path) { - return FileUtils.getTmpDir() + StringUtils.SLASH + Paths.get(path).getFileName().toString(); - } - /** * 服务商 */