From e697d575980fde36f449cd0c0716a358b374efce Mon Sep 17 00:00:00 2001 From: Afly Date: Thu, 7 Dec 2023 15:24:26 +0800 Subject: [PATCH 1/2] =?UTF-8?q?REPORT-110235=20fix:=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E4=BF=9D=E7=95=99Metadata=E7=9A=84=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin.xml | 2 +- .../fanruan/fs/s3/repository/core/S3Config.java | 15 +++++++++++++++ .../s3/repository/core/S3ResourceRepository.java | 16 +++++++++------- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/plugin.xml b/plugin.xml index 1a05e19..191d7fd 100644 --- a/plugin.xml +++ b/plugin.xml @@ -11,7 +11,7 @@ richie + [2023-11-21]小文件不使用分片上传, 新增preserveMetadata后台配置。
[2023-08-08]分片上传逻辑优化,模板保存问题修复。
[2023-07-24]支持大文件分片上传。
[2023-06-30]修复默认配置获取错误的问题,过滤有问题的路径。
diff --git a/src/main/java/com/fanruan/fs/s3/repository/core/S3Config.java b/src/main/java/com/fanruan/fs/s3/repository/core/S3Config.java index 976a9b8..f54bd9e 100644 --- a/src/main/java/com/fanruan/fs/s3/repository/core/S3Config.java +++ b/src/main/java/com/fanruan/fs/s3/repository/core/S3Config.java @@ -41,6 +41,9 @@ public class S3Config extends CommonRepoConfig { @Identifier("maxConnections") private Conf maxConnections = HolderKit.simple(200); + @Identifier("preserveMetadata") + private Conf preserveMetadata = HolderKit.simple(true); + @GetConfig("endPoint") public String getEndPoint() { return endPoint.get(); @@ -111,6 +114,16 @@ public class S3Config extends CommonRepoConfig { this.maxConnections.set(maxConnections); } + @GetConfig("preserveMetadata") + public boolean isPreserveMetadata() { + return preserveMetadata.get(); + } + + @SetConfig("preserveMetadata") + public void setPreserveMetadata(boolean preserveMetadata) { + this.preserveMetadata.set(preserveMetadata); + } + @Override public void update(String key) { super.update(key); @@ -123,6 +136,7 @@ public class S3Config extends CommonRepoConfig { this.setEnablePathStyleAccess(newConfig.isEnablePathStyleAccess()); this.setSignerOverride(newConfig.getSignerOverride()); this.setMaxConnections(newConfig.getMaxConnections()); + this.setPreserveMetadata(newConfig.isPreserveMetadata()); } } @@ -136,6 +150,7 @@ public class S3Config extends CommonRepoConfig { cloned.enablePathStyleAccess = (Conf) enablePathStyleAccess.clone(); cloned.signerOverride = (Conf) signerOverride.clone(); cloned.maxConnections = (Conf) maxConnections.clone(); + cloned.preserveMetadata = (Conf) preserveMetadata.clone(); return cloned; } } diff --git a/src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java b/src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java index 390dadd..ae37bb1 100644 --- a/src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java +++ b/src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java @@ -158,19 +158,21 @@ public class S3ResourceRepository extends BaseResourceRepository { if (length > MULTIPART_UPLOAD_LIMIT) { multipartUpload(path, new ByteArrayInputStream(data)); } else { - ObjectMetadata metadata; - try { - metadata = s3.getObjectMetadata(bucket, path); - } catch (Exception e) { + ObjectMetadata metadata = null; + if (preserveMetadata) { + try { + metadata = s3.getObjectMetadata(bucket, path); + } catch (Exception ignore) { + } + } + if (metadata == null) { metadata = new ObjectMetadata(); String mimeType = URLConnection.guessContentTypeFromName(path); if (mimeType != null) { metadata.setContentType(mimeType); } } - if (metadata != null) { - metadata.setContentLength(length); - } + metadata.setContentLength(length); s3.putObject(bucket, path, new ByteArrayInputStream(data), metadata); } } From 347f02c22bda29823774167692b537b275223331 Mon Sep 17 00:00:00 2001 From: Afly Date: Mon, 25 Dec 2023 11:56:19 +0800 Subject: [PATCH 2/2] =?UTF-8?q?REPORT-110235=20fix:=20=E6=BC=8F=E6=8F=90?= =?UTF-8?q?=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin.xml | 2 +- .../fanruan/fs/s3/repository/core/S3ResourceRepository.java | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/plugin.xml b/plugin.xml index 191d7fd..a4581f7 100644 --- a/plugin.xml +++ b/plugin.xml @@ -5,7 +5,7 @@ com.fanruan.fs yes no - 1.4.1 + 1.4.2 11.0~11.0 2023-03-14 richie diff --git a/src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java b/src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java index ae37bb1..6fcb290 100644 --- a/src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java +++ b/src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java @@ -57,6 +57,8 @@ public class S3ResourceRepository extends BaseResourceRepository { public static final String HTTP = "http:"; + private final boolean preserveMetadata; + private final AmazonS3 s3; private final String bucket; @@ -83,6 +85,7 @@ public class S3ResourceRepository extends BaseResourceRepository { amazonS3ClientBuilder = amazonS3ClientBuilder.withClientConfiguration(clientConfiguration); this.s3 = amazonS3ClientBuilder.build(); this.bucket = config.getBucket(); + this.preserveMetadata = config.isPreserveMetadata(); } @Override @@ -271,7 +274,7 @@ public class S3ResourceRepository extends BaseResourceRepository { try { s3.putObject(req); } catch (Exception e) { - LogKit.error("[S3] Failed to create parent path {}", path); + LogKit.error("[S3] Failed to create path {}", path); return false; } return true;