2015-04-27 59 views
0

在給定存儲區的所有必要權限的情況下,使用由aws sdk生成的預留網址訪問文件時出現問題。Aws iOS sdk提供「SignatureDoesNotMatch」錯誤的預先鏈接的網址

我已經從那裏下載了示例代碼github,並更改了以下內容 遵守供應商根據我的要求。

的變化低於

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

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

AWSServiceManager.defaultServiceManager.defaultServiceConfiguration = configuration; 

即使我成功地把文件上傳到AWS我不能使用presigned URL這是我從上傳的同時在AWS SDK獲得訪問它們。

任何人都可以指出我缺少的東西,以便使用預先登記的URL訪問文件。當URL在瀏覽器SignatureDoesNotMatch錯誤裝載

回答

0

問題是與presigned url編碼。在iOSandroid sdks(不在窗口中)您需要再次在Presigned url中對查詢字符串進行編碼。

NEWURL = baseurl +(編碼查詢字符串);

NEWURL是您可以訪問的正確網址。

它爲我工作。

1

最可能的原因爲「SignatureDoesNotMatch」是在報頭字段中的內容是從而產生presigned URL提供的一個不同。

下面的代碼片段演示如何生成和使用presigned 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]; 
0

試試這個,你需要註冊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"]; 
相關問題