From 903d810edc4eaad729b268912413e9987776d5fa Mon Sep 17 00:00:00 2001 From: 疯狂的狮子Li <15040126243@163.com> Date: 星期五, 21 六月 2024 12:34:50 +0800 Subject: [PATCH] fix 修复 新版上传未设置acl问题 --- ruoyi-common/ruoyi-common-oss/src/main/java/org/dromara/common/oss/core/OssClient.java | 13 ++++++++----- 1 files changed, 8 insertions(+), 5 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 d0c4537..aefbbd0 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 @@ -162,13 +162,14 @@ /** * 涓婁紶鏂囦欢鍒� Amazon S3锛屽苟杩斿洖涓婁紶缁撴灉 * - * @param filePath 鏈湴鏂囦欢璺緞 - * @param key 鍦� Amazon S3 涓殑瀵硅薄閿� - * @param md5Digest 鏈湴鏂囦欢鐨� MD5 鍝堝笇鍊硷紙鍙�夛級 + * @param filePath 鏈湴鏂囦欢璺緞 + * @param key 鍦� Amazon S3 涓殑瀵硅薄閿� + * @param md5Digest 鏈湴鏂囦欢鐨� MD5 鍝堝笇鍊硷紙鍙�夛級 + * @param contentType 鏂囦欢鍐呭绫诲瀷 * @return UploadResult 鍖呭惈涓婁紶鍚庣殑鏂囦欢淇℃伅 * @throws OssException 濡傛灉涓婁紶澶辫触锛屾姏鍑鸿嚜瀹氫箟寮傚父 */ - public UploadResult upload(Path filePath, String key, String md5Digest) { + public UploadResult upload(Path filePath, String key, String md5Digest, String contentType) { try { // 鏋勫缓涓婁紶璇锋眰瀵硅薄 FileUpload fileUpload = transferManager.uploadFile( @@ -176,6 +177,7 @@ y -> y.bucket(properties.getBucketName()) .key(key) .contentMD5(StringUtils.isNotEmpty(md5Digest) ? md5Digest : null) + .contentType(contentType) .build()) .addTransferListener(LoggingTransferListener.create()) .source(filePath).build()); @@ -221,6 +223,7 @@ y -> y.bucket(properties.getBucketName()) .key(key) .contentType(contentType) + .acl(getAccessPolicy().getObjectCannedACL()) .build()) .build()); @@ -362,7 +365,7 @@ * @throws OssException 濡傛灉涓婁紶澶辫触锛屾姏鍑鸿嚜瀹氫箟寮傚父 */ public UploadResult uploadSuffix(File file, String suffix) { - return upload(file.toPath(), getPath(properties.getPrefix(), suffix), null); + return upload(file.toPath(), getPath(properties.getPrefix(), suffix), null, FileUtils.getMimeType(suffix)); } /** -- Gitblit v1.9.3