我正在努力让 S3TransferUtilitySampleObjC 项目与我的 Cognito 和AWS凭据一起使用。
不幸的是我收到以下错误:
AWSURLSessionManager.m line:566 | -[AWSURLSessionManager printHTTPHeadersForResponse:] | Response headers:
{
Connection = "keep-alive";
"Content-Length" = 111;
"Content-Type" = "application/x-amz-json-1.1";
Date = "Mon, 16 Jan 2017 17:17:50 GMT";
"x-amzn-ErrorMessage" = "Unauthenticated access is not supported for this identity pool.";
"x-amzn-ErrorType" = "NotAuthorizedException:";
"x-amzn-RequestId" = "xxxxxxxxx-xxxxx-xxxxx-xxxx-xxxxxxx";
}
你能帮忙吗?
代码(注意我只从SecondViewController中删除了一些代码并修改了Constants中的值 - 我还修改了Info.plist文件(见下面的截图)
我目前只关注来自S3存储桶的下载文件。 因此我只修改了以下内容:
// In Constants.m
NSString *const S3BucketName = @"mybucketname";
NSString *const S3DownloadKeyName = @"config.plist";
// In SecondViewController.m
#import "SecondViewController.h"
#import "AppDelegate.h"
#import <AWSS3/AWSS3.h>
#import "Constants.h"
@interface SecondViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UIProgressView *progressView;
@property (weak, nonatomic) IBOutlet UILabel *statusLabel;
@property (copy, nonatomic) AWSS3TransferUtilityDownloadCompletionHandlerBlock completionHandler;
@property (copy, nonatomic) AWSS3TransferUtilityProgressBlock progressBlock;
@end
@implementation SecondViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.progressView.progress = 0;
self.statusLabel.text = @"Ready";
__weak SecondViewController *weakSelf = self;
self.completionHandler = ^(AWSS3TransferUtilityDownloadTask *task, NSURL *location, NSData *data, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (error) {
weakSelf.statusLabel.text = @"Failed to Download";
}
if (data) {
weakSelf.statusLabel.text = @"Successfully Downloaded";
weakSelf.imageView.image = [UIImage imageWithData:data];
weakSelf.progressView.progress = 1.0;
}
});
};
self.progressBlock = ^(AWSS3TransferUtilityTask *task, NSProgress *progress) {
dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.progressView.progress = progress.fractionCompleted;
});
};
AWSS3TransferUtility *transferUtility = [AWSS3TransferUtility defaultS3TransferUtility];
[transferUtility enumerateToAssignBlocksForUploadTask:nil downloadTask:^(AWSS3TransferUtilityDownloadTask * _Nonnull downloadTask, AWSS3TransferUtilityProgressBlock _Nullable __autoreleasing * _Nullable downloadProgressBlockReference, AWSS3TransferUtilityDownloadCompletionHandlerBlock _Nullable __autoreleasing * _Nullable completionHandlerReference) {
NSLog(@"%lu", (unsigned long)downloadTask.taskIdentifier);
*downloadProgressBlockReference = weakSelf.progressBlock;
*completionHandlerReference = weakSelf.completionHandler;
dispatch_async(dispatch_get_main_queue(), ^{
self.statusLabel.text = @"Uploading...";
});
}];
}
- (IBAction)start:(id)sender {
self.imageView.image = nil;
AWSS3TransferUtilityDownloadExpression *expression = [AWSS3TransferUtilityDownloadExpression new];
expression.progressBlock = self.progressBlock;
AWSS3TransferUtility *transferUtility = [AWSS3TransferUtility defaultS3TransferUtility];
[[transferUtility downloadDataFromBucket:S3BucketName
key:S3DownloadKeyName
expression:expression
completionHander:self.completionHandler] continueWithBlock:^id(AWSTask *task) {
if (task.error) {
NSLog(@"Error: %@", task.error);
}
if (task.exception) {
NSLog(@"Exception: %@", task.exception);
}
if (task.result) {
dispatch_async(dispatch_get_main_queue(), ^{
self.statusLabel.text = @"Downloading...";
});
}
return nil;
}];
}
Info.plist 文件修改于:
答案 0 :(得分:2)
您遇到的错误是解释问题 - 您作为未经身份验证的用户向Cognito发送请求,这意味着没有包含/链接到该身份的登录信息,但未启用为游泳池。
未经身份验证的身份是身份池的选择加入功能,您必须在从Cognito控制台创建/编辑池时启用它。