Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS S3 putobject with public read permissions - .Net SDK

I am using the .Net SDK for AWS.

I want to put a file into S3 and make its content readable by public, I see that I can use the "Grants" property in order to do this, however I cant find the value inputs in the online documentation for some of the fields.

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")}}
};

In the above request:

1) The grantee "Everyone" is just my guess, what should be the valid value there?

2) For S3Permission what is the valid value equivalent to my guess of "open/download"?

I understand I have to make list permission open to public at the bucket level as well, I can do everything via the console, I just can't seem to find the valid API request parameters.

like image 946
Sumit Maingi Avatar asked Aug 12 '15 05:08

Sumit Maingi


1 Answers

got my answer in AWS forum @ https://forums.aws.amazon.com/message.jspa?messageID=671223

Re-posting it here for ease:

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
};

This would upload the file, and set it with Public Read permissions.

In case you get "Access Denied" errors, make sure you have "PutObjectAcl" permission in your IAM policy.

like image 60
Sumit Maingi Avatar answered Oct 18 '22 20:10

Sumit Maingi