Aws iOS sdk Pre-singed url 给出 "SignatureDoesNotMatch" 错误
Aws iOS sdk Pre-singed url giving "SignatureDoesNotMatch" error
使用 aws sdk 生成的预签名 url 访问文件时遇到问题,给定存储桶的所有必要权限。
我已经从那里下载了示例代码 github 并更改了以下内容
Awscredential 提供商 根据我的要求。
变化如下
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.
访问文件
在浏览器中加载 url 时显示 SignatureDoesNotMatch 错误
"SignatureDoesNotMatch" 最可能的原因是 header-field 中的内容与生成预签名 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];
问题出在预签名 url 编码上。在 iOS 和 android sdks(不在 windows 中)你需要 再次在预签名 url 中对查询字符串 进行编码。
NEWURL=baseurl +(编码查询字符串);
NEWURL 是您可以访问的正确 url。
对我有用。
试试这个,您需要注册 PreSignedURL 生成器。
AWSStaticCredentialsProvider *credentialsProvider =[[AWSStaticCredentialsProvider alloc] initWithAccessKey:S3AccessKey secretKey:S3secretKey];
AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:credentialsProvider];
AWSServiceManager.defaultServiceManager.defaultServiceConfiguration = configuration;
// Register S3 PreSignedURL Builder
[AWSS3PreSignedURLBuilder registerS3PreSignedURLBuilderWithConfiguration:configuration forKey:@"configuration_name"];
AWSS3PreSignedURLBuilder * urlBuilder = [AWSS3PreSignedURLBuilder S3PreSignedURLBuilderForKey:@"configuration_name"];
使用 aws sdk 生成的预签名 url 访问文件时遇到问题,给定存储桶的所有必要权限。
我已经从那里下载了示例代码 github 并更改了以下内容 Awscredential 提供商 根据我的要求。
变化如下
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.
访问文件在浏览器中加载 url 时显示 SignatureDoesNotMatch 错误
"SignatureDoesNotMatch" 最可能的原因是 header-field 中的内容与生成预签名 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];
问题出在预签名 url 编码上。在 iOS 和 android sdks(不在 windows 中)你需要 再次在预签名 url 中对查询字符串 进行编码。
NEWURL=baseurl +(编码查询字符串);
NEWURL 是您可以访问的正确 url。
对我有用。
试试这个,您需要注册 PreSignedURL 生成器。
AWSStaticCredentialsProvider *credentialsProvider =[[AWSStaticCredentialsProvider alloc] initWithAccessKey:S3AccessKey secretKey:S3secretKey];
AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:credentialsProvider];
AWSServiceManager.defaultServiceManager.defaultServiceConfiguration = configuration;
// Register S3 PreSignedURL Builder
[AWSS3PreSignedURLBuilder registerS3PreSignedURLBuilderWithConfiguration:configuration forKey:@"configuration_name"];
AWSS3PreSignedURLBuilder * urlBuilder = [AWSS3PreSignedURLBuilder S3PreSignedURLBuilderForKey:@"configuration_name"];