You need to enable JavaScript to run this app.
导航

删除桶(iOS SDK)

最近更新时间2024.02.04 18:30:59

首次发布时间2022.11.21 19:11:16

本文介绍删除桶的示例代码。

前提条件

  • 已删除存储桶中的所有对象。
  • 已删除所有未完成合并的分片。
  • 若存在多版本对象,确保已经删除所有版本的对象。

示例代码

如下代码展示如何删除空桶。

// 从STS服务获取的临时访问密钥和安全令牌(AccessKey、SecretKey、SecurityToken)
TOSCredential *credential = [[TOSCredential alloc] initWithAccessKey:@"accesskey" secretKey:@"secretkey" securityToken:@"securityToken"];
TOSEndpoint *tosEndpoint = [[TOSEndpoint alloc] initWithURLString:@"endpoint" withRegion:@"region"];
TOSClientConfiguration *config = [[TOSClientConfiguration alloc] initWithEndpoint:tosEndpoint credential:credential];
TOSClient *client = [[TOSClient alloc] initWithConfiguration:config];

TOSDeleteBucketInput *delete = [TOSDeleteBucketInput new];
delete.tosBucket = @"bucket-name";
task = [client deleteBucket:delete];
[task continueWithBlock:^id(TOSTask *task) {
    if (!task.error) {
        NSLog(@"Delete bucket success.");
        TOSDeleteBucketOutput *output = task.result;
    } else {
        NSLog(@"Delete bucket failed, error: %@" ,task.error);
    }
    return nil;
}];