我正在尝试为 AWS S3 创建一个签名的 url,我只想要我存储桶中文件的 URL,我不想将它用于上传/下载。
我按照亚马逊文档中的步骤尝试了 AFNetworking,现在正在使用 AWS iOS 开发工具包。
到目前为止,我有这个:
AWSStaticCredentialsProvider *credentialsProvider = [AWSStaticCredentialsProvider credentialsWithAccessKey:@"Access Key" secretKey:@"secret key"];
AWSServiceConfiguration *configuration = [AWSServiceConfiguration configurationWithRegion:AWSRegionUSWest2 credentialsProvider:credentialsProvider];
[AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration;
AWSS3PreSignedURLBuilder * urlBuilder = [[AWSS3PreSignedURLBuilder alloc] initWithConfiguration:configuration];
AWSS3GetPreSignedURLRequest *preSignedURLRequest = [AWSS3GetPreSignedURLRequest new];
preSignedURLRequest.bucket = @"bucket-name";
preSignedURLRequest.key = @"/filename";
preSignedURLRequest.HTTPMethod = AWSHTTPMethodGET;
preSignedURLRequest.expires = [NSDate dateWithTimeIntervalSinceNow:3600];
NSURL *preSignedURL = [urlBuilder getPreSignedURL:preSignedURLRequest];
NSLog(@"%@", preSignedURL);
我收到很多关于代码被贬值的错误,但更重要的是我知道 getPreSignedURL 方法返回一个类型(AWSTask *),我的问题是如何将 AWSTask 转换为签名的 url?
此外,我不打算将密钥留在我的代码中,这只是暂时的测试。
如果有人可以帮助我找到如何获取 preSignedURL,那将是一个很大的帮助。谢谢