Browse Source

Pull request #648: REPORT-110235 fix: 新增是否保留Metadata的配置

Merge in PG/plugin-repository-s3 from ~AFLY/plugin-repository-s3:release/11.0 to release/11.0

* commit 'af3030e1d401860ac1bff4e010fd171decdd6b8d':
  REPORT-110235 fix: 新增是否保留Metadata的配置
release/11.0
Afly-储泓飞 1 year ago
parent
commit
05785ebf85
  1. 2
      plugin.xml
  2. 15
      src/main/java/com/fanruan/fs/s3/repository/core/S3Config.java
  3. 16
      src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java

2
plugin.xml

@ -11,7 +11,7 @@
<vendor>richie</vendor>
<description><![CDATA[使用支持S3协议的云存储文件系统作为文件服务器。]]></description>
<change-notes><![CDATA[
[2023-11-21]小文件不使用分片上传。 <br/>
[2023-11-21]小文件不使用分片上传, 新增preserveMetadata后台配置<br/>
[2023-08-08]分片上传逻辑优化,模板保存问题修复。 <br/>
[2023-07-24]支持大文件分片上传。 <br/>
[2023-06-30]修复默认配置获取错误的问题,过滤有问题的路径。 <br/>

15
src/main/java/com/fanruan/fs/s3/repository/core/S3Config.java

@ -41,6 +41,9 @@ public class S3Config extends CommonRepoConfig {
@Identifier("maxConnections")
private Conf<Integer> maxConnections = HolderKit.simple(200);
@Identifier("preserveMetadata")
private Conf<Boolean> 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<Boolean>) enablePathStyleAccess.clone();
cloned.signerOverride = (Conf<String>) signerOverride.clone();
cloned.maxConnections = (Conf<Integer>) maxConnections.clone();
cloned.preserveMetadata = (Conf<Boolean>) preserveMetadata.clone();
return cloned;
}
}

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

Loading…
Cancel
Save