简体   繁体   English

如何使用 AWS Java SDK V2 公开 S3 object?

[英]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?如何通过 AWS Java SDK V2.2.41 公开 S3 object?

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? 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.您可以使用 CannedAccessControlList.PublicRead 属性通过 AWS Java SDK 创建公共对象。

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

Well, at last found the answer: We can use好吧,终于找到了答案:我们可以使用

.acl(ObjectCannedACL.PUBLIC_READ) .acl(ObjectCannedACL.PUBLIC_READ)

with PutObjectRequest as under:使用 PutObjectRequest 如下:

    PutObjectResponse putObjRes = s3Client.putObject(
            PutObjectRequest.builder()
                    .bucket("bucket")
                    .key("key)
                    .acl(ObjectCannedACL.PUBLIC_READ)
                    .build(), RequestBody.fromFile(<file>));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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