Get the ACL of a bucket (iOS SDK)

更新时间:
复制 MD 格式

Query the access control list (ACL) of an OSS bucket to determine who can read or write its objects.

Prerequisites

Before you begin, make sure you have:

  • An initialized OSSClient instance (see Initialization for setup instructions)

When initializing OSSClient, specify an endpoint that matches the region of the bucket.

Bucket ACLs

A bucket ACL controls who can access objects in the bucket. OSS supports three ACL values:

ACLValueAccess
PrivateprivateOnly the bucket owner and authorized users have read and write permissions. All other users are denied access.
Public-readpublic-readOnly the bucket owner and authorized users have read and write permissions. All other users have read-only access. Use with caution.
Public-read-writepublic-read-writeAll users have read and write permissions. Use with caution.

Query the bucket ACL

The following code queries the ACL of a bucket named examplebucket. The result is returned in result.aclGranted as a string: private, public-read, or public-read-write.

OSSGetBucketACLRequest *request = [OSSGetBucketACLRequest new];
// Specify the bucket name.
request.bucketName = @"examplebucket";

OSSTask *getBucketACLTask = [client getBucketACL:request];
[getBucketACLTask continueWithBlock:^id(OSSTask *task) {
    if (!task.error) {
        OSSGetBucketACLResult *result = task.result;
        // aclGranted returns "private", "public-read", or "public-read-write".
        NSLog(@"ACL: %@", result.aclGranted);
    } else {
        NSLog(@"get bucket ACL failed, error: %@", task.error);
    }
    return nil;
}];

// Optional: block until the task completes.
// [getBucketACLTask waitUntilFinished];

What's next