gpt4 book ai didi

ios - Aws iOS sdk Pre-singed url 给出 "SignatureDoesNotMatch"错误

转载 作者:行者123 更新时间:2023-11-29 02:04:53 27 4
gpt4 key购买 nike

在授予存储桶所有必要权限的情况下,使用 aws sdk 生成的预签名 URL 访问文件时遇到问题。

我已经从 github 下载了示例代码并更改了以下内容Awcredential 提供商按照我的要求。

更改如下

AWSStaticCredentialsProvider *credentialsProvider =[[AWSStaticCredentialsProvider alloc] initWithAccessKey:S3AccessKey secretKey:S3secretKey];

AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:credentialsProvider];

AWSServiceManager.defaultServiceManager.defaultServiceConfiguration = configuration;

即使我将文件成功上传到 aws,我也无法使用上传时从 aws sdk 获取的预签名 URL 访问它们。

任何人都可以指出我在使用预签名网址访问文件时缺少的内容吗?

在浏览器中加载 url 时显示 SignatureDoesNotMatch 错误

最佳答案

“SignatureDoesNotMatch”最可能的原因是 header 字段中的内容与生成预签名 url 时提供的内容不同。

以下代码片段演示了如何使用预签名 url 生成和下载文件:

AWSS3GetPreSignedURLRequest *getPreSignedURLRequest = [AWSS3GetPreSignedURLRequest new];
getPreSignedURLRequest.bucket = @"bucketname";
getPreSignedURLRequest.key = @"keyname";
getPreSignedURLRequest.HTTPMethod = AWSHTTPMethodGET;
getPreSignedURLRequest.expires = [NSDate dateWithTimeIntervalSinceNow:3600];

AWSS3PreSignedURLBuilder *preSignedURLBuilder = [AWSS3PreSignedURLBuilder defaultS3PreSignedURLBuilder];

[[[preSignedURLBuilder getPreSignedURL:getPreSignedURLRequest] continueWithBlock:^id(BFTask *task) {

if (task.error) {
XCTAssertNil(task.error);
return nil;
}

NSURL *presignedURL = task.result;
//NSLog(@"(GET)presigned URL is: %@",presignedURL.absoluteString);

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:presignedURL];
request.cachePolicy = NSURLRequestReloadIgnoringLocalCacheData;

NSError *returnError = nil;
NSHTTPURLResponse *returnResponse = nil;

NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&returnResponse error:&returnError];

return nil;
}] waitUntilFinished];

关于ios - Aws iOS sdk Pre-singed url 给出 "SignatureDoesNotMatch"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29899518/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com