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

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. 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 from the bucket. We recommend that you exercise with caution when you set the bucket ACL to public read. public-read
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. public-read-write

For more information about ACLs, see Access control in OSS Developer Guide.

The following code provides an example on how to call putBucketACL configure bucket ACLs:

let OSS = require('ali-oss');

let client = new OSS({
  region: '<Your region>',
  accessKeyId: '<Your AccessKeyId>',
  accessKeySecret: '<Your AccessKeySecret>'
});

async function putBucketACL() {
  try {
    const result = await client.putBucketACL('bucket name', 'public-read');
    console.log(result);
  } catch (err) {
    console.log(err);
  }
}

putBucketACL();
			

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

Query the ACL of a bucket

The following code provides an example on how to call getBucketACL to query the ACL of a bucket:

let OSS = require('ali-oss');

let client = new OSS({
  region: '<Your region>',
  accessKeyId: '<Your AccessKeyId>',
  accessKeySecret: '<Your AccessKeySecret>'
});

async function getBucketACL() {
  try {
    const result = await client.getBucketACL('luozhang002');
    console.log(result);
  } catch (err) {
    console.log(err);
  }
}

getBucketACL();
			

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