Merge pull request #376 from iflytek/fix/oss-chunked-encoding

fix(storage): disable chunked encoding for Aliyun OSS compatibility
This commit is contained in:
dongmucat 2026-05-08 17:22:51 +08:00 • committed by GitHub
commit aecdecccab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 21 additions and 1 deletions

View file

@ -40,6 +40,8 @@ SKILLHUB_STORAGE_S3_ACCESS_KEY=replace-me
SKILLHUB_STORAGE_S3_SECRET_KEY=replace-me
SKILLHUB_STORAGE_S3_REGION=cn-shanghai
SKILLHUB_STORAGE_S3_FORCE_PATH_STYLE=false
# Aliyun OSS rejects aws-chunked encoding; set to true when targeting Aliyun OSS.
SKILLHUB_STORAGE_S3_DISABLE_CHUNKED_ENCODING=true
SKILLHUB_STORAGE_S3_AUTO_CREATE_BUCKET=false
SKILLHUB_STORAGE_S3_PRESIGN_EXPIRY=PT10M

View file

@ -120,6 +120,7 @@ skillhub:
secret-key: ${SKILLHUB_STORAGE_S3_SECRET_KEY:}
region: ${SKILLHUB_STORAGE_S3_REGION:us-east-1}
force-path-style: ${SKILLHUB_STORAGE_S3_FORCE_PATH_STYLE:true}
disable-chunked-encoding: ${SKILLHUB_STORAGE_S3_DISABLE_CHUNKED_ENCODING:false}
auto-create-bucket: ${SKILLHUB_STORAGE_S3_AUTO_CREATE_BUCKET:false}
presign-expiry: ${SKILLHUB_STORAGE_S3_PRESIGN_EXPIRY:PT10M}
max-connections: ${SKILLHUB_STORAGE_S3_MAX_CONNECTIONS:100}

View file

@ -15,6 +15,7 @@ public class S3StorageProperties {
private String secretKey;
private String region = "us-east-1";
private boolean forcePathStyle = true;
private boolean disableChunkedEncoding = false;
private boolean autoCreateBucket = false;
private Duration presignExpiry = Duration.ofMinutes(10);
private Integer maxConnections = 100;
@ -36,6 +37,8 @@ public class S3StorageProperties {
public void setRegion(String region) { this.region = region; }
public boolean isForcePathStyle() { return forcePathStyle; }
public void setForcePathStyle(boolean forcePathStyle) { this.forcePathStyle = forcePathStyle; }
public boolean isDisableChunkedEncoding() { return disableChunkedEncoding; }
public void setDisableChunkedEncoding(boolean disableChunkedEncoding) { this.disableChunkedEncoding = disableChunkedEncoding; }
public boolean isAutoCreateBucket() { return autoCreateBucket; }
public void setAutoCreateBucket(boolean autoCreateBucket) { this.autoCreateBucket = autoCreateBucket; }
public Duration getPresignExpiry() { return presignExpiry; }

View file

@ -78,7 +78,10 @@ public class S3StorageService implements ObjectStorageService {
var builder = S3Client.builder()
.region(Region.of(properties.getRegion()))
.credentialsProvider(buildCredentialsProvider())
.forcePathStyle(properties.isForcePathStyle())
.serviceConfiguration(S3Configuration.builder()
.pathStyleAccessEnabled(properties.isForcePathStyle())
.chunkedEncodingEnabled(!properties.isDisableChunkedEncoding())
.build())
.httpClientBuilder(httpClientBuilder)
.overrideConfiguration(config -> config
.apiCallAttemptTimeout(properties.getApiCallAttemptTimeout())

View file

@ -39,6 +39,17 @@ import static org.mockito.Mockito.when;
class S3StorageServiceTest {
@Test
void buildS3ClientShouldDisableChunkedEncodingWhenConfigured() {
S3StorageProperties props = createProperties(true);
props.setDisableChunkedEncoding(true);
S3StorageService service = new S3StorageService(props);
ApacheHttpClient.Builder httpClientBuilder = ApacheHttpClient.builder();
S3Client client = service.buildS3Client(httpClientBuilder);
assertThat(client).isNotNull();
client.close();
}
@Test
void shouldUsePathStylePresignedUrlWhenForcePathStyleEnabled() {
URI presignedUrl = presignGetObjectUrl(true);