Skip to content
Draft
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@

> 例如百度云提供 `s3.bj.bcebos.com` 和 `<bucket-name>.s3.bj.bcebos.com` 两种 Endpoint,请填写`s3.bj.bcebos.com`。

### 启用分块传输编码

默认关闭。若经过反向代理(如 Cloudflare Tunnel、Ingress)导致请求被改为 `Transfer-Encoding: chunked` 并移除 `Content-Length`,服务端签名校验可能不一致而返回 403,可开启该选项以提升兼容性。

### Access Key & Access Secret

与服务商自己 API 的 Access Key 和 Access Secret 相同,详情查看对应服务商的文档。
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/run/halo/s3os/S3LinkServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import run.halo.app.extension.ListOptions;
import run.halo.app.extension.MetadataUtil;
import run.halo.app.extension.ReactiveExtensionClient;
import run.halo.app.extension.index.query.QueryFactory;
import run.halo.app.extension.index.query.Queries;
import run.halo.app.extension.router.selector.FieldSelector;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.HeadObjectRequest;
Expand Down Expand Up @@ -91,7 +91,7 @@ public Mono<S3ListResult> listObjects(String policyName, String continuationToke
// 获取已经关联的附件并标记
ListOptions listOptions = new ListOptions();
listOptions.setFieldSelector(
FieldSelector.of(QueryFactory.equal("spec.policyName", policyName)));
FieldSelector.of(Queries.equal("spec.policyName", policyName)));
return client.listAll(Attachment.class, listOptions, Sort.unsorted())
.doOnNext(attachment -> {
S3ListResult.ObjectVo objectVo =
Expand Down Expand Up @@ -133,7 +133,7 @@ private Mono<Set<String>> getExistingAttachments(Set<String> objectKeys,
String policyName) {
ListOptions listOptions = new ListOptions();
listOptions.setFieldSelector(
FieldSelector.of(QueryFactory.equal("spec.policyName", policyName)));
FieldSelector.of(Queries.equal("spec.policyName", policyName)));
return client.listAll(Attachment.class, listOptions, Sort.unsorted())
.filter(attachment -> StringUtils.isNotBlank(
MetadataUtil.nullSafeAnnotations(attachment).get(S3OsAttachmentHandler.OBJECT_KEY))
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/run/halo/s3os/S3OsAttachmentHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ S3Client buildS3Client(S3OsProperties properties) {
.credentialsProvider(() -> AwsBasicCredentials.create(properties.getAccessKey(),
properties.getAccessSecret()))
.serviceConfiguration(S3Configuration.builder()
.chunkedEncodingEnabled(false)
.chunkedEncodingEnabled(Boolean.TRUE.equals(properties.getEnableChunkedEncoding()))
.pathStyleAccessEnabled(properties.getEnablePathStyleAccess())
.build())
.build();
Expand All @@ -328,7 +328,7 @@ private S3Presigner buildS3Presigner(S3OsProperties properties) {
.credentialsProvider(() -> AwsBasicCredentials.create(properties.getAccessKey(),
properties.getAccessSecret()))
.serviceConfiguration(S3Configuration.builder()
.chunkedEncodingEnabled(false)
.chunkedEncodingEnabled(Boolean.TRUE.equals(properties.getEnableChunkedEncoding()))
.pathStyleAccessEnabled(properties.getEnablePathStyleAccess())
.build())
.build();
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/run/halo/s3os/S3OsProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class S3OsProperties {

private Boolean enablePathStyleAccess = false;

private Boolean enableChunkedEncoding = false;

private String endpoint;

private String accessKey;
Expand Down
10 changes: 10 additions & 0 deletions src/main/resources/extensions/policy-template-s3os.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ spec:
value: true
value: false
validation: required
- $formkit: select
name: enableChunkedEncoding
label: 启用分块传输编码
options:
- label: 关闭
value: false
- label: 开启
value: true
value: false
help: 反向代理可能会移除 Content-Length 请求头,从而导致签名不一致发生 403 错误,可以尝试开启此选项
- $formkit: text
name: endpoint
label: EndPoint
Expand Down