diff --git a/README.md b/README.md index 6dc35ab..2cfecc3 100644 --- a/README.md +++ b/README.md @@ -134,6 +134,12 @@ * **加随机字母后缀:** 如遇重名,会在文件名后加上4位的随机字母后缀,例如`image.png`会变成`image_abcd.png`。 * **报错不上传** 如遇重名,会放弃上传,并在用户界面提示 Duplicate filename 错误。 +### 自定义 User-Agent + +可选配置项,仅当您的 S3 服务提供商要求校验客户端 UA 时填写,默认留空不影响任何原有功能。 + +> 例如中国科技云数据胶囊要求密钥必须绑定应用,绑定 Rclone 应用后此处需要填写 `rclone/v1.67.0` 才能正常访问。 + ## 部分对象存储服务商兼容性 |服务商|文档|兼容访问风格|兼容性| @@ -151,6 +157,7 @@ |又拍云||Virtual Hosted Style /
Path Style|✅| |自建minio|\-|Path Style|✅| |华为云|文档未说明是否兼容,工单反馈不保证兼容性,实际测试可以使用|Virtual Hosted Style|❓| +|中国科技云数据胶囊||Path Style|✅| |Ucloud|只支持 8MB 大小的分片,本插件暂不支持
|\-|❌| ## 开发环境 diff --git a/src/main/java/run/halo/s3os/S3OsAttachmentHandler.java b/src/main/java/run/halo/s3os/S3OsAttachmentHandler.java index cf4af2c..34b1178 100644 --- a/src/main/java/run/halo/s3os/S3OsAttachmentHandler.java +++ b/src/main/java/run/halo/s3os/S3OsAttachmentHandler.java @@ -307,7 +307,7 @@ Attachment buildAttachment(S3OsProperties properties, ObjectDetail objectDetail) } S3Client buildS3Client(S3OsProperties properties) { - return S3Client.builder() + var builder = S3Client.builder() .region(Region.of(properties.getRegion())) .endpointOverride( URI.create(properties.getEndpointProtocol() + "://" + properties.getEndpoint())) @@ -316,8 +316,12 @@ S3Client buildS3Client(S3OsProperties properties) { .serviceConfiguration(S3Configuration.builder() .chunkedEncodingEnabled(false) .pathStyleAccessEnabled(properties.getEnablePathStyleAccess()) - .build()) - .build(); + .build()); + if (StringUtils.isNotBlank(properties.getUserAgent())) { + builder.overrideConfiguration(config -> + config.putHeader("User-Agent", properties.getUserAgent())); + } + return builder.build(); } private S3Presigner buildS3Presigner(S3OsProperties properties) { diff --git a/src/main/java/run/halo/s3os/S3OsProperties.java b/src/main/java/run/halo/s3os/S3OsProperties.java index 3d10e4a..d096feb 100644 --- a/src/main/java/run/halo/s3os/S3OsProperties.java +++ b/src/main/java/run/halo/s3os/S3OsProperties.java @@ -48,6 +48,12 @@ public class S3OsProperties { private String region = "Auto"; + /** + * Custom User-Agent header for S3 requests, optional. + * Useful for services that validate client application binding like CSTCloud. + */ + private String userAgent = ""; + private List urlSuffixes; private String thumbnailParamPattern; diff --git a/src/main/resources/extensions/policy-template-s3os.yaml b/src/main/resources/extensions/policy-template-s3os.yaml index 25943d7..26a5e3f 100644 --- a/src/main/resources/extensions/policy-template-s3os.yaml +++ b/src/main/resources/extensions/policy-template-s3os.yaml @@ -68,6 +68,11 @@ spec: label: Region placeholder: 如不填写,则默认为 Auto help: 若 Region 为 Auto 无法使用,才需要填写对应 Region,Cloudflare R2 需要填写均为小写字母的 auto + - $formkit: text + name: userAgent + label: 自定义 User-Agent + placeholder: 如 Rclone、S3Drive 等,留空则使用默认值 + help: 部分对象存储服务(如中国科技云数据胶囊)会校验请求客户端类型,绑定 Rclone 应用后此处填 `rclone/v1.67.0` 即可正常使用 - $formkit: text name: location label: 上传目录