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

创建桶(iOS SDK)

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

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

桶(Bucket)是TOS的全局唯一的命名空间,相当于数据的容器,用来储存对象(Object)数据。新创建的桶名在 TOS 中必须是唯一的。

示例代码

如下代码展示如何创建一个新桶。

// 从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];

TOSCreateBucketInput *create = [TOSCreateBucketInput new];
create.tosBucket = @"bucket-name";
create.tosAcl = TOSACLPublicRead;
TOSTask *task = [client createBucket:create];
[task continueWithBlock:^id _Nullable(TOSTask * _Nonnull task) {
    if (!task.error) {
        NSLog(@"Create bucket success.");
        TOSCreateBucketOutput *output = task.result;
    } else {
        NSLog(@"Create bucket failed, error: %@.", task.error);
    }
    return nil;
}];