Object Storage Service (OSS) allows you to manage the access control lists (ACLs) of both buckets and objects. You can configure the ACL of an object when you upload the object or modify the ACL of an uploaded object.

Object ACLs

The following table describes the ACLs that you can configure for an object.

ACL Description Value
Inherited from the bucket The ACL of the object is the same as the ACL of the bucket in which the object is stored. default
Private Only the object owner and authorized users are granted the read and write permissions on the object. private
Public read Only the object owner and authorized users are granted the read and write permissions on the object. Other users are granted only the read permissions on the object. Exercise caution when you set the ACL of the object to this value. public-read
Public read/write All users are granted the read and write permissions on the object. Exercise caution when you set the ACL of the object to this value. public-read-write

Configure the ACL of an object

The following code provides an example on how to configure the ACL of a specified object:

const oss = require('ali-oss');

const store = oss({ 
  // Specify the region in which the bucket is located. For example, if your bucket is located in the China (Hangzhou) region, set the region to oss-cn-hangzhou. 
  region: 'yourregion',
  // The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations in OSS is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. 
  accessKeyId: 'yourAccessKeyId',
  accessKeySecret: 'yourAccessKeySecret',
  // Set yourbucketname to the name of your bucket. 
  bucket: 'yourbucketname'
});
  // yourObjectName specifies the complete path of the object. The path cannot contain the bucket name. Example: example/test.txt. 
await store.putACL('yourObjectName', 'public-read');

Query the ACL of an object

The following code provides an example on how to query the ACL of a specified object:

const oss = require('ali-oss');

const store = oss({
  // Specify the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the region to oss-cn-hangzhou. 
  region: 'yourregion',
  // The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations in OSS is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. 
  accessKeyId: 'yourAccessKeyId',
  accessKeySecret: 'yourAccessKeySecret',
  // Set yourbucketname to the name of your bucket. 
  bucket: 'yourbucketname',
});
  // yourObjectName specifies the complete path of the object. The path cannot contain the bucket name. Example: example/test.txt. 
const result = await store.getACL('yourObjectName');
console.log(result.acl);

References

  • For the complete sample code that is used to manage the ACL of an object, visit GitHub.
  • For more information about the API operation that you can call to configure the ACL of an object, see PutObjectACL.
  • For more information about the API operation that you can call to query the ACL of an object, see GetObjectACL.