【问题标题】:Aws iOS sdk Pre-singed url giving "SignatureDoesNotMatch" errorAws iOS sdk Pre-singed url 给出“SignatureDoesNotMatch”错误
【发布时间】:2015-07-06 03:05:50
【问题描述】:

使用 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 错误

【问题讨论】:

    标签: ios amazon-web-services amazon-s3 aws-sdk


    【解决方案1】:

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

    这里有一段代码 sn-p 来演示如何使用预签名的 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];
    

    【讨论】:

      【解决方案2】:

      问题在于预签名的 url 编码。在 iOSandroid sdks(不在 Windows 中)中,您需要再次在 Presigned url 中编码查询字符串

      NEWURL=baseurl +(编码查询字符串);

      NEWURL 是您可以访问的正确网址。

      它对我有用。

      【讨论】:

        【解决方案3】:

        试试这个,你需要注册 PreSignedURL builder。

        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"];
        

        【讨论】:

          猜你喜欢
          • 2016-10-12
          • 1970-01-01
          • 2018-04-09
          • 1970-01-01
          • 1970-01-01
          • 2014-12-31
          • 1970-01-01
          • 2021-06-21
          • 2019-01-29
          相关资源
          最近更新 更多