You need to enable JavaScript to run this app.
导航
列举多版本对象(iOS SDK)
最近更新时间:2024.02.04 18:31:00首次发布时间:2022.11.21 19:11:16

本文介绍列举桶内的多版本对象的示例代码,每次最大返回 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];

TOSListObjectVersionsInput *listVersions = [[TOSListObjectVersionsInput alloc] init];
listVersions.tosBucket = @"bucket-name";
TOSTask *task = [client listObjectVersions:listVersions];
[task continueWithBlock:^id(TOSTask *task) {
    if (!task.error) {
        NSLog(@"List object versions success.");
        TOSListObjectVersionsOutput *output = task.result;
    } else {
        NSLog(@"List object versions failed, error: %@" ,task.error);
    }
    return nil;
}];