Sets an S3AccessControlList on the specified bucket or object.
Declaration Syntax
C# |
public SetACLResponse SetACL( SetACLRequest request )
Parameters
- request (SetACLRequest)
- The SetACLRequest that defines the parameters of the operation.
Return Value
Returns a SetACLResponse from S3.
Remarks
Each bucket and object in Amazon S3 has an ACL that defines its access control policy, which is a list of grants. A grant consists of one grantee and one permission. ACLs only grant permissions; they do not deny them.
Often used ACLs are defined in the S3CannedACL enumeration.
Examples
This example shows how to set a canned ACL on an object, first to PublicRead, then back to Private.
CopySetACL sample 1
// Create a client AmazonS3Client client = new AmazonS3Client(); // Set Canned ACL (PublicRead) for an existing item client.SetACL(new SetACLRequest { BucketName = "SampleBucket", Key = "Item1", CannedACL = S3CannedACL.PublicRead }); // Set Canned ACL (PublicRead) for an existing item // (This reverts ACL back to default for object) client.SetACL(new SetACLRequest { BucketName = "SampleBucket", Key = "Item1", CannedACL = S3CannedACL.Private });
This example shows how to get and set ACLs on an object.
CopyGetACL\SetACL samples
// Create a client AmazonS3Client client = new AmazonS3Client(); // Retrieve ACL for object S3AccessControlList acl = client.GetACL(new GetACLRequest { BucketName = "SampleBucket", Key = "Item1", }).AccessControlList; // Retrieve owner Owner owner = acl.Owner; // Describe grant S3Grant grant = new S3Grant { Grantee = new S3Grantee { EmailAddress = "sample@example.com" }, Permission = S3Permission.WRITE_ACP }; // Create new ACL S3AccessControlList newAcl = new S3AccessControlList { Grants = new List<S3Grant> { grant }, Owner = owner }; // Set new ACL SetACLResponse response = client.SetACL(new SetACLRequest { BucketName = "SampleBucket", Key = "Item1", ACL = acl });
Exceptions
Exception | Condition |
---|---|
ArgumentNullException | |
WebException | |
AmazonS3Exception |
See Also