如何使用AFNetworking获取S3 Bucket Location

时间:2016-03-21 18:40:25

标签: amazon-web-services amazon-s3 afnetworking

我已经设法让AFAmazonS3Manager用于列出存储桶,getObject,putObject和deleteObject,但我似乎无法让它用于获取存储桶所在的区域。

我用于请求的代码是:

-(void)getBucketLocation:(NSString *)bucketName {

  AFAmazonS3Manager *s3Manager = [[AFAmazonS3Manager alloc] initWithAccessKeyID:self.accessKey secret:self.secretKey];
  [s3Manager.requestSerializer setBucket:bucketName];

  [s3Manager GET:@"/?location" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
    //do something with successful response
  } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSString *xmlResponse = [[NSString alloc] initWithData:operation.responseData encoding:NSUTF8StringEncoding];
    NSLog(@"Didn't get bucket location: %@", error);
  }];
}

响应始终返回403-forbidden error,xmlResponse字符串包含<Error><Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message>

访问密钥和秘密访问密钥与我用于列表,放置,删除和获取请求的密钥相同,并且IAM用户具有“s3:GetBucketLocation”的权限。

切换到AWS iOS SDK是我最后的选择,但如果可以,我宁愿坚持使用AFAmazonS3Manager的相对简单性。有什么指针吗?谢谢!

0 个答案:

没有答案