简体   繁体   中英

How to make an S3 object public using AWS Java SDK V2?

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?

You can use the CannedAccessControlList.PublicRead property to create public objects through AWS Java SDK.

s3client.putObject(putObjectRequest.withCannedAcl(CannedAccessControlList.PublicRead))

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>));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM