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);
}
}