PutACL() public method

Sets the permissions on a bucket using access control lists (ACL).
public PutACL ( PutACLRequest request ) : PutACLResponse
request PutACLRequest Container for the necessary parameters to execute the PutACL service method.
return PutACLResponse
コード例 #1
0
ファイル: RegionsTest.cs プロジェクト: rajdotnet/aws-sdk-net
        public void TestPostUpload()
        {
            var region = RegionEndpoint.USWest1;

            using (var client = new AmazonS3Client(region))
            {
                var bucketName = S3TestUtils.CreateBucket(client);
                client.PutACL(new PutACLRequest
                {
                    BucketName = bucketName,
                    CannedACL = S3CannedACL.BucketOwnerFullControl
                });

                var credentials = GetCredentials(client);
                try
                {
                    var response = testPost("foo/bar/content.txt", bucketName, testContentStream("Line one\nLine two\nLine three\n"), "", credentials, region);
                    Assert.IsNotNull(response.RequestId);
                    Assert.IsNotNull(response.HostId);
                    Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
                }
                finally
                {
                    AmazonS3Util.DeleteS3BucketWithObjects(client, bucketName);
                }
            }
        }
コード例 #2
0
        public virtual void MakeObjectPublic(AmazonS3Client s3Client, string bucketName, string key)
        {
            // Create the request
            var putAclRequest = new PutACLRequest {
                BucketName = bucketName,
                Key = key,
                CannedACL = S3CannedACL.PublicRead
            };

            // Submit the request
            s3Client.PutACL(putAclRequest);
        }
コード例 #3
0
        public void AclSamples()
        {
            {
                #region PutACL Sample 1

                // Create a client
                AmazonS3Client client = new AmazonS3Client();

                // Set Canned ACL (PublicRead) for an existing item
                client.PutACL(new PutACLRequest
                {
                    BucketName = "SampleBucket",
                    Key = "Item1",
                    CannedACL = S3CannedACL.PublicRead
                });

                // Set Canned ACL (PublicRead) for an existing item
                // (This reverts ACL back to default for object)
                client.PutACL(new PutACLRequest
                {
                    BucketName = "SampleBucket",
                    Key = "Item1",
                    CannedACL = S3CannedACL.Private
                });

                #endregion
            }

            {
                #region GetACL\PutACL 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 = "*****@*****.**" },
                    Permission = S3Permission.WRITE_ACP
                };

                // Create new ACL
                S3AccessControlList newAcl = new S3AccessControlList
                {
                    Grants = new List<S3Grant> { grant },
                    Owner = owner
                };

                // Set new ACL
                PutACLResponse response = client.PutACL(new PutACLRequest
                {
                    BucketName = "SampleBucket",
                    Key = "Item1",
                    AccessControlList = acl
                });

                #endregion
            }
        }