存储桶是存储对象的容器,该操作可以判断桶是否存在,以及获取桶的元数据。
如下代码展示如何获取桶的元数据。
// 从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]; TOSHeadBucketInput *head = [TOSHeadBucketInput new]; head.tosBucket = @"bucket-name"; TOSTask *task = [client headBucket:head]; [task continueWithBlock:^id(TOSTask *task) { if (!task.error) { NSLog(@"Head bucket success."); TOSHeadBucketOutput *output = task.result; } else { NSLog(@"Head bucket failed, error: %@" ,task.error); } return nil; }];