存储桶是存储对象的容器,该操作会返回所有桶列表。
如下代码展示如何列举所有的桶。
// 从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];
TOSListBucketsInput *listBuckets = [TOSListBucketsInput new];
TOSTask *task = [client listBuckets:listBuckets];
[task continueWithBlock:^id(TOSTask *task) {
if (!task.error) {
NSLog(@"List buckets success.");
TOSListBucketsOutput *output = task.result;
} else {
NSLog(@"List buckets failed, error: %@" ,task.error);
}
return nil;
}];