删除Bucket
更新时间:2022-10-21
基本流程
- 创建BOSClient类的实例;
- 执行BOSClient deleteBucket方法;
- 删除失败时会产生错误。
示例代码
__block BOSDeleteBucketResponse* response = nil;
BCETask* task = [client deleteBucket:@"<bucketname>"];
task.then(^(BCEOutput* output) {
if (output.response) {
response = (BOSDeleteBucketResponse*)output.response;
NSLog(@"delete bucket success!");
}
if (output.error) {
NSLog(@"delete bucket failure");
}
});
[task waitUtilFinished];
注意:如果Bucket不为空(即Bucket中有Object和未完成的三步上传Part存在),则Bucket无法被删除,必须清空Bucket后才能成功删除。
完整示例
#import <BaiduBCEBasic/BaiduBCEBasic.h>
#import <BaiduBCEBOS/BaiduBCEBOS.h>
void example(void) {
// 初始化
BCECredentials* credentials = [[BCECredentials alloc] init];
credentials.accessKey = @"<access key>";
credentials.secretKey = @"<secret key>";
BOSClientConfiguration* configuration = [[BOSClientConfiguration alloc] init];
configuration.credentials = credentials;
BOSClient* client = [[BOSClient alloc] initWithConfiguration:configuration];
__block BOSDeleteBucketResponse* response = nil;
BCETask* task = [client deleteBucket:@"<bucketname>"];
task.then(^(BCEOutput* output) {
if (output.response) {
response = (BOSDeleteBucketResponse*)output.response;
NSLog(@"delete bucket success!");
}
if (output.error) {
NSLog(@"delete bucket failure");
}
});
[task waitUtilFinished];
}