You need to enable JavaScript to run this app.
对象存储

对象存储

复制全文
iOS
临时访问授权(iOS SDK)
复制全文
临时访问授权(iOS SDK)

TosClient 在向服务端发起请求时,默认会在请求 Header 里包含签名。SDK 也支持构造带签名的 URL,可直接用该 URL 发起 HTTP 请求,也可以将该 URL 共享给第三方实现访问授权。

示例代码

如下代码展示如何生成带签名的 URL。

TOSCredential *credential = [[TOSCredential alloc] initWithAccessKey:@"accesskey" secretKey:@"secretkey"];
TOSEndpoint *tosEndpoint = [[TOSEndpoint alloc] initWithURLString:@"endpoint" withRegion:@"region"];
TOSClientConfiguration *config = [[TOSClientConfiguration alloc] initWithEndpoint:tosEndpoint credential:credential];
TOSClient *client = [[TOSClient alloc] initWithConfiguration:config];

TOSPreSignedURLInput *input = [TOSPreSignedURLInput new];
input.tosBucket = @"bucket-name";
input.tosKey = @"object-name";
input.tosHttpMethod = TOSHTTPMethodTypeGet;
TOSTask *task = [client preSignedURL:input];
[task continueWithBlock:^id _Nullable(TOSTask * _Nonnull task) {
    if (!task.error) {
        NSLog(@"Presigned success.");
        TOSPreSignedURLOutput *output = task.result;
        NSString *url = output.tosSignedUrl;
    } else {
        NSLog(@"Presigned failed, error: %@.", task.error);
    }
    return nil;
}];
最近更新时间:2024.02.04 18:30:59
这个页面对您有帮助吗?
有用
有用
无用
无用