Skip to content

Commit

Permalink
Apply ObjectMetadata to S3Template.createSignedPutURL request (#974)
Browse files Browse the repository at this point in the history
Also added contentLength property to ObjectMetadata
  • Loading branch information
LucasJC authored Dec 3, 2023
1 parent 250575d commit e722d3a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public class ObjectMetadata {
@Nullable
private final String contentLanguage;

@Nullable
private final Long contentLength;

@Nullable
private final String contentType;

Expand Down Expand Up @@ -119,21 +122,22 @@ public static Builder builder() {

ObjectMetadata(@Nullable String acl, @Nullable String cacheControl, @Nullable String contentDisposition,
@Nullable String contentEncoding, @Nullable String contentLanguage, @Nullable String contentType,
@Nullable Instant expires, @Nullable String grantFullControl, @Nullable String grantRead,
@Nullable String grantReadACP, @Nullable String grantWriteACP, @Nullable Map<String, String> metadata,
@Nullable String serverSideEncryption, @Nullable String storageClass,
@Nullable String websiteRedirectLocation, @Nullable String sseCustomerAlgorithm,
@Nullable String sseCustomerKey, @Nullable String sseCustomerKeyMD5, @Nullable String ssekmsKeyId,
@Nullable String ssekmsEncryptionContext, @Nullable Boolean bucketKeyEnabled, @Nullable String requestPayer,
@Nullable String tagging, @Nullable String objectLockMode, @Nullable Instant objectLockRetainUntilDate,
@Nullable String objectLockLegalHoldStatus, @Nullable String expectedBucketOwner,
@Nullable String checksumAlgorithm) {
@Nullable Long contentLength, @Nullable Instant expires, @Nullable String grantFullControl,
@Nullable String grantRead, @Nullable String grantReadACP, @Nullable String grantWriteACP,
@Nullable Map<String, String> metadata, @Nullable String serverSideEncryption,
@Nullable String storageClass, @Nullable String websiteRedirectLocation,
@Nullable String sseCustomerAlgorithm, @Nullable String sseCustomerKey, @Nullable String sseCustomerKeyMD5,
@Nullable String ssekmsKeyId, @Nullable String ssekmsEncryptionContext, @Nullable Boolean bucketKeyEnabled,
@Nullable String requestPayer, @Nullable String tagging, @Nullable String objectLockMode,
@Nullable Instant objectLockRetainUntilDate, @Nullable String objectLockLegalHoldStatus,
@Nullable String expectedBucketOwner, @Nullable String checksumAlgorithm) {
this.acl = acl;
this.cacheControl = cacheControl;
this.contentDisposition = contentDisposition;
this.contentEncoding = contentEncoding;
this.contentLanguage = contentLanguage;
this.contentType = contentType;
this.contentLength = contentLength;
this.expires = expires;
this.grantFullControl = grantFullControl;
this.grantRead = grantRead;
Expand Down Expand Up @@ -177,6 +181,9 @@ void apply(PutObjectRequest.Builder builder) {
if (contentType != null) {
builder.contentType(contentType);
}
if (contentLength != null) {
builder.contentLength(contentLength);
}
if (expires != null) {
builder.expires(expires);
}
Expand Down Expand Up @@ -333,6 +340,9 @@ void apply(CreateMultipartUploadRequest.Builder builder) {
}

void apply(UploadPartRequest.Builder builder) {
if (contentLength != null) {
builder.contentLength(contentLength);
}
if (sseCustomerAlgorithm != null) {
builder.sseCustomerAlgorithm(sseCustomerAlgorithm);
}
Expand Down Expand Up @@ -401,6 +411,11 @@ public String getContentType() {
return contentType;
}

@Nullable
public Long getContentLength() {
return contentLength;
}

@Nullable
public Instant getExpires() {
return expires;
Expand Down Expand Up @@ -533,6 +548,9 @@ public static class Builder {
@Nullable
private String contentType;

@Nullable
private Long contentLength;

@Nullable
private Instant expires;

Expand Down Expand Up @@ -630,6 +648,11 @@ public Builder contentType(@Nullable String contentType) {
return this;
}

public Builder contentLength(@Nullable Long contentLength) {
this.contentLength = contentLength;
return this;
}

public Builder expires(Instant expires) {
this.expires = expires;
return this;
Expand Down Expand Up @@ -767,11 +790,11 @@ public Builder checksumAlgorithm(@Nullable ChecksumAlgorithm checksumAlgorithm)

public ObjectMetadata build() {
return new ObjectMetadata(acl, cacheControl, contentDisposition, contentEncoding, contentLanguage,
contentType, expires, grantFullControl, grantRead, grantReadACP, grantWriteACP, metadata,
serverSideEncryption, storageClass, websiteRedirectLocation, sseCustomerAlgorithm, sseCustomerKey,
sseCustomerKeyMD5, ssekmsKeyId, ssekmsEncryptionContext, bucketKeyEnabled, requestPayer, tagging,
objectLockMode, objectLockRetainUntilDate, objectLockLegalHoldStatus, expectedBucketOwner,
checksumAlgorithm);
contentType, contentLength, expires, grantFullControl, grantRead, grantReadACP, grantWriteACP,
metadata, serverSideEncryption, storageClass, websiteRedirectLocation, sseCustomerAlgorithm,
sseCustomerKey, sseCustomerKeyMD5, ssekmsKeyId, ssekmsEncryptionContext, bucketKeyEnabled,
requestPayer, tagging, objectLockMode, objectLockRetainUntilDate, objectLockLegalHoldStatus,
expectedBucketOwner, checksumAlgorithm);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public URL createSignedPutURL(String bucketName, String key, Duration duration,

PutObjectRequest.Builder putObjectRequestBuilder = PutObjectRequest.builder().bucket(bucketName).key(key);
if (metadata != null) {
putObjectRequestBuilder.metadata(metadata.getMetadata());
metadata.apply(putObjectRequestBuilder);
}
if (contentType != null) {
putObjectRequestBuilder.contentType(contentType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void canBeAppliedToPutObjectRequest() {
Instant now = Instant.now();
ObjectMetadata objectMetadata = ObjectMetadata.builder().acl("acl").cacheControl("cacheControl")
.contentDisposition("contentDisposition").contentEncoding("contentEncoding")
.contentLanguage("contentLanguage").contentType("contentType").expires(now)
.contentLanguage("contentLanguage").contentType("contentType").contentLength(0L).expires(now)
.grantFullControl("grantFullControl").grantRead("grantRead").grantReadACP("grantReadACP")
.grantWriteACP("grantWriteACP").metadata("key1", "value1").metadata("key2", "value2")
.serverSideEncryption("serverSideEncryption").storageClass("storageClass")
Expand Down

0 comments on commit e722d3a

Please sign in to comment.