如何通过Web服务API将某个S3文件标记为“公开”。

最佳答案

使用方法setCannedAcl(CannedAccessControlList.PublicRead)更改访问控制权限。阅读Java文档以获取详细信息here

示例代码:

BasicAWSCredentials basicAWSCredentials = new BasicAWSCredentials(ACCESS_KEY,SECRET_KEY);
AmazonS3 s3 = new AmazonS3Client(basicAWSCredentials);

PutObjectRequest putObj = new PutObjectRequest(bucketName, objectKey, fileToUpload);

// making the object Public
putObj.setCannedAcl(CannedAccessControlList.PublicRead);

s3.putObject(putObj);

08-18 13:36