本文介绍列举对象的示例代码,默认返回最大 1000 个对象。
如下代码展示如何列举对象。
// 从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]; TOSListObjectsInput *list = [TOSListObjectsInput new]; list.tosBucket = @"tos-test"; TOSTask *task = [_client listObjects:list]; [task continueWithBlock:^id(TOSTask *task) { if (!task.error) { NSLog(@"List objects success."); TOSListObjectsOutput *output = task.result; } else { NSLog(@"List objects failed, error: %@" ,task.error); } return nil; }];