JoséMi
JoséMi

Reputation: 11952

Sign AWS S3 link (including versioning) in Java

I've the folowing code that signs a URL to an object inside an S3 Bucket

https://docs.aws.amazon.com/AmazonS3/latest/dev/ShareObjectPreSignedURLJavaSDK.html

Now, if the Bucket has versioning enabled, how can I sign a specific version of the object link?

Upvotes: 1

Views: 434

Answers (1)

luk2302
luk2302

Reputation: 57114

Call withVersionId(String):

GeneratePresignedUrlRequest generatePresignedUrlRequest = 
                new GeneratePresignedUrlRequest(bucketName, objectKey)
                .withMethod(HttpMethod.GET)
                .withExpiration(expiration)
                .withVersionId("yourVesionId");

Sets the version ID of the object, only present if versioning has been enabled for the bucket.

Upvotes: 3

Related Questions