A bucket is a container for objects stored in OSS. Every object is contained in a bucket. This topic describes how to query 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 the 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 in 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. Exercise caution when set the bucket ACL to public read/write. public-read-write

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

GetBucketACLRequest getBucketACLRequest = new GetBucketACLRequest("<bucketName>");

// Query the ACL of the bucket.
OSSAsyncTask getBucketAclTask = oss.asyncGetBucketACL(getBucketACLRequest, new OSSCompletedCallback<GetBucketACLRequest, GetBucketACLResult>() {
    @Override
    public void onSuccess(GetBucketACLRequest request, GetBucketACLResult result) {
        Log.d("asyncGetBucketACL", "Success!") ;
        Log.d("BucketAcl", result.getBucketACL());
        Log.d("Owner", result.getBucketOwner());
        Log.d("ID", result.getBucketOwnerID());
    }
    @Override
    public void onFailure(GetBucketACLRequest request, ClientException clientException, ServiceException serviceException) {
        // Handle request exceptions.
        if (clientException ! = null) {
            // Handle client exceptions, such as network exceptions.
            clientException.printStackTrace();
        }
        if (serviceException ! = null) {
            // Handle service exceptions.
            Log.e("ErrorCode", serviceException.getErrorCode());
            Log.e("RequestId", serviceException.getRequestId());
            Log.e("HostId", serviceException.getHostId());
            Log.e("RawMessage", serviceException.getRawMessage());
        }
    }
});
Note
  • Three ACLs are available for a bucket: public read/write, public read, and private.
  • Only the owner of a bucket can call the GetBucketAcl API operation on the bucket.
  • The returned result contains the bucket ACL, ID of the bucket owner, and the name of the bucket owner (consistent with the ID).
  • For more information about how to query the ACL of a bucket, see GetBucketAcl.