Create New Bucket
Updated at:2025-11-03
Basic workflow
- Instantiate the BOSClient class.
- To execute the BOSClient.putBucket() method, you need to specify the bucket name.
Example code
Swift
1BCETask* task = [client putBucket:@"<bucketname>"]; //Create a new bucket and specify the bucket name
Complete example
Swift
1#import <BaiduBCEBasic/BaiduBCEBasic.h>
2#import <BaiduBCEBOS/BaiduBCEBOS.h>
3void example(void) {
4// Initialize
5BCECredentials* credentials = [[BCECredentials alloc] init];
6credentials.accessKey = @"<access key>";
7credentials.secretKey = @"<secret key>";
8BOSClientConfiguration* configuration = [[BOSClientConfiguration alloc] init];
9configuration.credentials = credentials;
10BOSClient* client = [[BOSClient alloc] initWithConfiguration:configuration];
11BCETask* task = [client putBucket:@"<bucketName>"];
12task.then(^(BCEOutput* output) { // The task can be executed asynchronously.
13 if (output.response) {
14// Task executed successfully.
15 }
16 if (output.error) {
17// Task execution failed.
18 }
19 if (output.progress) {
20// Task execution progress.
21 }
22});
23[task waitUtilFinished]; // You can wait synchronously until the task is finished.
24}
Note: Since bucket names are globally unique across all regions, ensure the BucketName does not conflict with any existing BucketName in other regions.
