Delete bucket
Updated at:2025-11-03
Basic workflow
- Create an instance of the BOSClient class.
- Execute the BOSClient deleteBucket method;
- An error occurs if the deletion process fails.
Example code
Swift
1__block BOSDeleteBucketResponse* response = nil;
2BCETask* task = [client deleteBucket:@"<bucketname>"];
3task.then(^(BCEOutput* output) {
4 if (output.response) {
5 response = (BOSDeleteBucketResponse*)output.response;
6 NSLog(@"delete bucket success!");
7 }
8 if (output.error) {
9 NSLog(@"delete bucket failure");
10 }
11});
12[task waitUtilFinished];
Note: A bucket cannot be deleted if it is not empty (i.e., it contains objects or unfinished multipart uploads). The bucket must be emptied before successful deletion.
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];
11__block BOSDeleteBucketResponse* response = nil;
12BCETask* task = [client deleteBucket:@"<bucketname>"];
13task.then(^(BCEOutput* output) {
14 if (output.response) {
15 response = (BOSDeleteBucketResponse*)output.response;
16 NSLog(@"delete bucket success!");
17 }
18 if (output.error) {
19 NSLog(@"delete bucket failure");
20 }
21});
22[task waitUtilFinished];
23}
