Reputation: 39
How do you make an S3 object public via the AWS Java SDK V2.2.41?
Specifically, what API methods via the Java AWS SDK V2 can be used to make an Object public when it's being uploaded or we make an existing uploaded object publicly readable?
Upvotes: 1
Views: 1771
Reputation: 39
Well, at last found the answer: We can use
.acl(ObjectCannedACL.PUBLIC_READ)
with PutObjectRequest as under:
PutObjectResponse putObjRes = s3Client.putObject(
PutObjectRequest.builder()
.bucket("bucket")
.key("key")
.acl(ObjectCannedACL.PUBLIC_READ)
.build(), RequestBody.fromFile(<file>));
Upvotes: 2
Reputation: 159
You can use the CannedAccessControlList.PublicRead property to create public objects through AWS Java SDK.
s3client.putObject(putObjectRequest.withCannedAcl(CannedAccessControlList.PublicRead))
Upvotes: 0