Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@
* **加随机字母后缀:** 如遇重名,会在文件名后加上4位的随机字母后缀,例如`image.png`会变成`image_abcd.png`。
* **报错不上传** 如遇重名,会放弃上传,并在用户界面提示 Duplicate filename 错误。

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

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

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

|服务商|文档|兼容访问风格|兼容性|
Expand All @@ -149,8 +154,9 @@
|Cloudflare|<https://developers.cloudflare.com/r2/data-access/s3-api/>|Virtual Hosted Style / <br>Path Style|✅|
| Oracle Cloud |<https://docs.oracle.com/en-us/iaas/Content/Object/Tasks/s3compatibleapi.htm>|Virtual Hosted Style / <br>Path Style|✅|
|又拍云|<https://help.upyun.com/knowledge-base/aws-s3%e5%85%bc%e5%ae%b9/>|Virtual Hosted Style / <br>Path Style|✅|
|自建minio|\-|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
9 changes: 6 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,11 @@ 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
17 changes: 10 additions & 7 deletions src/main/resources/extensions/policy-template-s3os.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ spec:
- $formkit: text
name: endpoint
label: EndPoint
placeholder: 请填写不带 bucket name 的 Endpoint
Comment thread
XiSoul marked this conversation as resolved.
placeholder: 请填写不带bucket-name的Endpoint
validation: required
help: 协议头请在上方设置,此处无需以 "http://" 或"https://"开头,系统会自动拼接
Comment thread
XiSoul marked this conversation as resolved.
help: 协议头请在上方设置,此处无需以"http://"或"https://"开头,系统会自动拼接
- $formkit: password
name: accessKey
label: Access Key ID
Expand All @@ -68,15 +68,18 @@ spec:
label: Region
placeholder: 如不填写,则默认为 Auto
help: 若 Region 为 Auto 无法使用,才需要填写对应 Region,Cloudflare R2 需要填写均为小写字母的 auto
- $formkit: text
name: userAgent
label: 自定义User-Agent
Comment thread
XiSoul marked this conversation as resolved.
Outdated
placeholder: 如Rclone、S3Drive等,留空则使用默认值
Comment thread
XiSoul marked this conversation as resolved.
Outdated
help: 部分对象存储服务(如中国科技云数据胶囊)会校验请求客户端类型,绑定Rclone应用后此处填`rclone/v1.67.0`即可正常使用
Comment thread
XiSoul marked this conversation as resolved.
Outdated
- $formkit: text
name: location
label: 上传目录
placeholder: 如不填写,则默认上传到根目录
help: 支持的占位符请查阅:https://github.com/halo-dev/plugin-s3#上传目录
- $formkit: select
name: randomFilenameMode
key: randomFilenameMode
Comment thread
XiSoul marked this conversation as resolved.
id: randomFilenameMode
label: 上传时重命名文件方式
options:
- label: 保留原文件名
Expand All @@ -102,13 +105,13 @@ spec:
label: 随机字母长度
min: 4
max: 16
if: "$get(randomFilenameMode).value == 'dateWithString' || $get(randomFilenameMode).value == 'datetimeWithString' || $get(randomFilenameMode).value == 'withString' || $get(randomFilenameMode).value == 'string'"
if: "$randomFilenameMode == 'dateWithString' || $randomFilenameMode == 'datetimeWithString' || $randomFilenameMode == 'withString' || $randomFilenameMode == 'string'"
Comment thread
XiSoul marked this conversation as resolved.
Outdated
help: 支持4~16位, 默认为8位
- $formkit: text
name: customTemplate
key: customTemplate
label: 自定义文件名模板
if: "$get(randomFilenameMode).value == 'custom'"
if: "$randomFilenameMode == 'custom'"
Comment thread
XiSoul marked this conversation as resolved.
Outdated
value: "${origin-filename}"
help: 支持的占位符请查阅:https://github.com/halo-dev/plugin-s3#自定义文件名模板
- $formkit: select
Expand All @@ -135,7 +138,7 @@ spec:
name: domain
label: 绑定域名(CDN域名)
placeholder: 如不设置,那么将使用 Bucket + EndPoint 作为域名
help: 协议头请在上方设置,此处无需以 "http://""https://" 开头,系统会自动拼接
Comment thread
XiSoul marked this conversation as resolved.
help: 协议头请在上方设置,此处无需以"http://""https://"开头,系统会自动拼接
- $formkit: repeater
name: urlSuffixes
label: 网址后缀
Expand Down
Loading