diff --git a/spring-cloud-aws-s3/src/main/java/io/awspring/cloud/s3/ObjectMetadata.java b/spring-cloud-aws-s3/src/main/java/io/awspring/cloud/s3/ObjectMetadata.java index 8913910ac..95a3a51ea 100644 --- a/spring-cloud-aws-s3/src/main/java/io/awspring/cloud/s3/ObjectMetadata.java +++ b/spring-cloud-aws-s3/src/main/java/io/awspring/cloud/s3/ObjectMetadata.java @@ -340,9 +340,6 @@ void apply(CreateMultipartUploadRequest.Builder builder) { } void apply(UploadPartRequest.Builder builder) { - if (contentLength != null) { - builder.contentLength(contentLength); - } if (sseCustomerAlgorithm != null) { builder.sseCustomerAlgorithm(sseCustomerAlgorithm); } diff --git a/spring-cloud-aws-s3/src/test/java/io/awspring/cloud/s3/ObjectMetadataTests.java b/spring-cloud-aws-s3/src/test/java/io/awspring/cloud/s3/ObjectMetadataTests.java index 351fb9a4f..f6213dc3d 100644 --- a/spring-cloud-aws-s3/src/test/java/io/awspring/cloud/s3/ObjectMetadataTests.java +++ b/spring-cloud-aws-s3/src/test/java/io/awspring/cloud/s3/ObjectMetadataTests.java @@ -26,6 +26,7 @@ import software.amazon.awssdk.services.s3.model.RequestPayer; import software.amazon.awssdk.services.s3.model.ServerSideEncryption; import software.amazon.awssdk.services.s3.model.StorageClass; +import software.amazon.awssdk.services.s3.model.UploadPartRequest; /** * Unit tests for {@link ObjectMetadata}. @@ -78,4 +79,17 @@ void mapsEnumsToString() { assertThat(result.checksumAlgorithm()).isEqualTo(ChecksumAlgorithm.CRC32); } + @Test + void doesNotApplyContentLengthForPartUpload() { + long objectContentLength = 16L; + long partContentLength = 8L; + ObjectMetadata metadata = ObjectMetadata.builder().contentLength(objectContentLength).build(); + + UploadPartRequest.Builder builder = UploadPartRequest.builder().contentLength(partContentLength); + metadata.apply(builder); + UploadPartRequest result = builder.build(); + + assertThat(result.contentLength()).isEqualTo(partContentLength); + } + }