All Products
Search
Document Center

Object Storage Service:Query information about a bucket by using OSS SDK for iOS

Last Updated:Aug 20, 2024

A bucket is a container used to store objects in Object Storage Service (OSS). All objects in OSS are stored in buckets. This topic describes how to query the information about a bucket.

Usage notes

  • Before you run the sample code in this topic, you must create an OSSClient instance by using methods such as using a custom domain name or Security Token Service (STS). For more information, see Initialization.

    Note

    When you initialize an OSSClient instance, specify an endpoint that maps to the region of the bucket.

Examples

The following sample code provides an example on how to query the information about a bucket named examplebucket, including the region, creation date, and ACL of the bucket:

OSSGetBucketInfoRequest *request = [OSSGetBucketInfoRequest new];
// Specify the name of the bucket. Example: examplebucket. 
request.bucketName = @"examplebucket";
// Query the information about the bucket. 
OSSTask * getBucketInfoTask = [client getBucketInfo:request];

[getBucketInfoTask continueWithBlock:^id(OSSTask *task) {
    if (!task.error) {
        OSSGetBucketInfoResult *result = task.result;
        NSLog(@"Creation time: %@", result.creationDate);
        NSLog(@"Region: %@", result. Location);
        NSLog(@"Storage class: %@", result.storageClass);
        NSLog(@"Owner: %@", result.owner.userName);
        NSLog(@"ACL: %@", result.acl.grant);
    } else {
        NSLog(@"get bucket info failed, error: %@", task.error);
    }
    return nil;
}];
// Implement synchronous blocking to wait for the task to complete. 
// [getBucketInfoTask waitUntilFinished];

References

  • For the complete sample code that is used to query information about a bucket, visit GitHub.

  • For more information about the API operation that you can call to query information about a bucket, see GetBucketInfo.

  • For more information about how to initialize an OSSClient instance, see Initialization.