我正在使用.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)受助人“Everyone”只是我的猜测,那里的有效值是什么?
2)对于S3Permission,有什么效果值相当于我对“开放/下载”的猜测?
我理解我必须在桶级别向公众开放列表权限,我可以通过控制台做任何事情,我似乎无法找到有效的API请求参数。
答案 0 :(得分:9)
在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
};
这将上传文件,并使用公共读取权限进行设置。
如果你得到“拒绝访问”#34;错误,确保你有&#34; PutObjectAcl&#34;您的IAM政策允许。
答案 1 :(得分:4)
对于仍在寻找答案的任何人,添加 ACL:'public-read'属性即可解决问题。
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<p>
<a class="btn btn-primary" data-toggle="collapse" href="#collapseExample" role="button" aria-expanded="false" aria-controls="collapseExample">
Link with href
</a>
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample">
Button with data-target
</button>
</p>
<div class="collapse" id="collapseExample">
<div class="card card-body">
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident.
</div>
</div>
答案 2 :(得分:0)
我已经解决了允许存储桶策略中的所有权限的问题
\ufeff