如何将某个S3文件标记为Make Public

时间:2012-04-07 13:47:37

标签: java amazon-s3 amazon-web-services

如何通过webservices API将某个S3文件标记为Make Public。

1 个答案:

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