A bucket is a container for objects stored in OSS. Every object is contained in a bucket. This topic describes how to configure and obtain the access control list (ACL) of a bucket.

Configure the ACL of a bucket

For the complete code used to configure the ACL of a bucket, visit GitHub.

The following table describes the ACLs for buckets.

ACL Description Value
Private Only the owner or authorized users of this bucket can read and write objects in the bucket. Other users, including anonymous users cannot access objects in the bucket without authorization. CannedAccessControlList.Private
Public read Only the owner or authorized users of this bucket can write objects in the bucket. Other users, including anonymous users can only read objects in the bucket. We recommend that you exercise caution when you set the bucket ACL to public read. CannedAccessControlList.PublicRead
Public read/write Any users, including anonymous users can read and write objects in the bucket. We recommend that you exercise caution when you set the bucket ACL to public read/write. CannedAccessControlList.PublicReadWrite

The following code provides an example on how to configure the ACL for a bucket:

using Aliyun.OSS;

// Initialize an OSSClient instance.
var client = new OssClient(endpoint, accessKeyId, accessKeySecret);

// Configure the ACL of the bucket.
public void SetBucketAcl(string bucketName)
{
    try
    {
        // Configure the ACL of the bucket to public read.
        client.SetBucketAcl(bucketName, CannedAccessControlList.PublicRead);
        Console.WriteLine("Set bucket ACL succeeded");
    }
    catch (Exception ex)
    {
        Console.WriteLine("Set bucket ACL failed. {0}", ex.Message);
    }
}
			

For more information about how to configure the ACL for a bucket, see PutBucketACL.

Query the ACL of a bucket

For the complete code used to query the ACL of a bucket, visit GitHub.

The following code provides an example on how to obtain the ACL of a bucket:

using Aliyun.OSS;

// Initialize an OSSClient instance.
var client = new OssClient(endpoint, accessKeyId, accessKeySecret);

// Query the ACL of the bucket.
public void GetBucketAcl(string bucketName)
{
    try
    {
        string bucketName = "your-bucket";
        var acl = client.GetBucketAcl(bucketName);

        Console.WriteLine("Get bucket ACL success", acl.ACL.ToString());
    }
    catch (Exception ex)
    {
        Console.WriteLine("Get bucket ACL failed. {0}", ex.Message);
    }
}
			

For more information about how to obtain the ACL of a bucket, see GetBucketAcl.