Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@
* **加随机字母后缀:** 如遇重名,会在文件名后加上4位的随机字母后缀,例如`image.png`会变成`image_abcd.png`。
* **报错不上传** 如遇重名,会放弃上传,并在用户界面提示 Duplicate filename 错误。

### 自定义 User-Agent

可选配置项,仅当您的 S3 服务提供商要求校验客户端 UA 时填写,默认留空不影响任何原有功能。

> 例如中国科技云数据胶囊要求密钥必须绑定应用,绑定 Rclone 应用后此处需要填写 `rclone/v1.67.0` 才能正常访问。

## 部分对象存储服务商兼容性

|服务商|文档|兼容访问风格|兼容性|
Expand All @@ -151,6 +157,7 @@
|又拍云|<https://help.upyun.com/knowledge-base/aws-s3%e5%85%bc%e5%ae%b9/>|Virtual Hosted Style / <br>Path Style|✅|
|自建minio|\-|Path Style|✅|
|华为云|文档未说明是否兼容,工单反馈不保证兼容性,实际测试可以使用|Virtual Hosted Style|❓|
|中国科技云数据胶囊|<https://www.cstcloud.cn/product/datacapsule>|Path Style|✅|
|Ucloud|只支持 8MB 大小的分片,本插件暂不支持<br><https://docs.ucloud.cn/ufile/s3/s3_introduction>|\-|❌|

## 开发环境
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/run/halo/s3os/S3OsAttachmentHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand All @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/run/halo/s3os/S3OsProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<urlSuffixItem> urlSuffixes;

private String thumbnailParamPattern;
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/extensions/policy-template-s3os.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: 上传目录
Expand Down