Warm tip: This article is reproduced from serverfault.com, please click

amazon s3-具有公共读取权限的AWS S3 putobject

(amazon s3 - AWS S3 putobject with public read permissions)

发布于 2015-08-12 05:30:07

我正在使用.Net SDK for AWS。

我想将文件放入S3并使其公开可读,我可以使用“ Grants”属性来执行此操作,但是在某些字段的在线文档中找不到值输入。

var request = new PutObjectRequest()
{
BucketName = "some-bucket",
Key = fileName,
FilePath = filePath,
StorageClass = new S3StorageClass("REDUCED_REDUNDANCY"),
ContentType = "text/csv",
Grants = new List<S3Grant>() {
new S3Grant() {
Grantee = new S3Grantee()
{
CanonicalUser = "Everyone",
DisplayName = "Everyone"
},
Permission = new S3Permission("open/download")}}
};

在以上要求中:

1)受赠人“所有人”只是我的猜测,那里的有效值应该是多少?

2)对于S3Permission,等效于我对“打开/下载”的猜测的有效值是多少?

我知道我也必须在存储桶级别向公众开放列表权限,我可以通过控制台执行所有操作,但似乎找不到有效的API请求参数。

Questioner
Sumit Maingi
Viewed
12
Sumit Maingi 2015-08-20 22:31:57

在AWS论坛上得到了我的答案@ https://forums.aws.amazon.com/message.jspa?messageID=671223

为方便起见,将其重新发布在这里:

http://docs.aws.amazon.com/sdkfornet1/latest/apidocs/html/T_Amazon_S3_Model_S3CannedACL.htm

var request = new PutObjectRequest()
{
    BucketName = "some-bucket",
    Key = fileName,
    FilePath = filePath,
    StorageClass = new S3StorageClass("REDUCED_REDUNDANCY"),
    ContentType = "text/csv",
    CannedACL = S3CannedACL.PublicRead
};

这将上传文件,并将其设置为“公共读取”权限。

如果出现“访问被拒绝”错误,请确保你的IAM策略具有“ PutObjectAcl”权限。