如何通过webservices API将某个S3文件标记为Make Public。
答案 0 :(得分:31)
使用方法 setCannedAcl(CannedAccessControlList.PublicRead)更改访问控制权限。阅读java doc了解详细信息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);