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
OSSClientinstance (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:
| ACL | Value | Access |
|---|---|---|
| Private | private | Only the bucket owner and authorized users have read and write permissions. All other users are denied access. |
| Public-read | public-read | Only the bucket owner and authorized users have read and write permissions. All other users have read-only access. Use with caution. |
| Public-read-write | public-read-write | All 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
For the complete sample code, see GitHub.
For the underlying REST API, see GetBucketAcl.
该文章对您有帮助吗?