Create a bucket (iOS SDK)

Updated at:

A bucket is a container that stores objects in Object Storage Service (OSS). All objects are stored in buckets. This topic describes how to create a bucket.

Notes

  • Before you use the sample code in this topic, create an OSSClient instance using a custom domain name or Security Token Service (STS). For more information, see Initialization (iOS SDK).

    Note

    The region of the bucket is determined by the endpoint that you specify during initialization.

  • Starting at 10:00:00 (UTC+8) on October 13, 2025, OSS gradually enables block public access by default for buckets that are created by calling API operations or by using OSS SDKs or ossutil in all regions. For the time when the change takes effect in each region, see Announcement.

Permissions

By default, an Alibaba Cloud account has full permissions. RAM users or RAM roles under an Alibaba Cloud account do not have any permissions by default. The Alibaba Cloud account or account administrator must grant operation permissions through RAM policies or Bucket Policy.

API

Action

Description

PutBucket

oss:PutBucket

Creates a bucket.

oss:PutBucketAcl

After creating a bucket, this permission is required to modify the bucket ACL.

Sample code

The following code shows how to create a bucket named examplebucket:

// Construct a request to create a bucket.
OSSCreateBucketRequest * create = [OSSCreateBucketRequest new];
// Set the bucket name to examplebucket.
create.bucketName = @"examplebucket";
// Set the access control list (ACL) of the bucket to private.
create.xOssACL = @"private";
// Set the storage class of the bucket to Infrequent Access (IA).
create.storageClass = OSSBucketStorageClassIA;

OSSTask * createTask = [client createBucket:create];

[createTask continueWithBlock:^id(OSSTask *task) {
    if (!task.error) {
        NSLog(@"create bucket success!");
    } else {
        NSLog(@"create bucket failed, error: %@", task.error);
    }
    return nil;
}];
// Block the current thread to wait for the task to complete.
// [createTask waitUntilFinished];          

References