我正试图从我的亚马逊S3桶(v2)下载一张图片,但我搞不懂。我一直从transferManager下载获得null :下载getting;
所有帐户详细信息/密钥都已填写完毕。任何帮助都是非常感谢的。
-(void) startApp:(NSDictionary *)launchOptions {
// create credentials
AWSCognitoCredentialsProvider *credentialsProvider = [AWSCognitoCredentialsProvider credentialsWithRegionType:AWSRegionUSEast1
accountId:@"xxxx-xxxx-xxxx"
identityPoolId: @"us-east-1:xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx"
unauthRoleArn:@"Cognito_AppUnauth_DefaultRole"
authRoleArn:nil];
AWSServiceConfiguration *configuration = [AWSServiceConfiguration configurationWithRegion:AWSRegionUSEast1
credentialsProvider:credentialsProvider];
[AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration;
}
- (instancetype) init {
AWSS3TransferManagerDownloadRequest *downloadRequest = [AWSS3TransferManagerDownloadRequest new];
downloadRequest.bucket = @"mybucket.s3.amazonaws.com";
downloadRequest.key = @"XXXXXXXXXXXXXXX";
downloadRequest.downloadingFileURL = [NSURL URLWithString:@"https://s3.amazonaws.com/MYBUCKET/hello.png"];
[self download:downloadRequest];
return self;
}
- (BFTask *)download:(AWSS3TransferManagerDownloadRequest *)downloadRequest {
NSLog(@"Download request: %@", downloadRequest);
AWSS3TransferManager *transferManager = [AWSS3TransferManager defaultS3TransferManager];
NSLog(@"%@", [transferManager download:downloadRequest]);
return nil;
}发布于 2015-02-17 00:50:51
首先,您滥用了AWSS3TransferManagerDownloadRequest的downloadingFileURL属性。downloadingFileURL不应该引用您正在从中获取的S3位置;相反,它应该引用您要将该文件写入的磁盘位置,例如:
NSString *downloadingFilePath = [NSTemporaryDirectory()stringByAppendingPathComponent:@"hello.png"];
NSURL *downloadingFileURL = [NSURL fileURLWithPath:downloadingFilePath];一旦该文件完成下载,它将出现在该文件路径。
不过,要知道您的文件什么时候准备好了,我建议在下面这样的块中执行下载请求:
[[transferManager download:downloadRequest]continueWithExecutor
[BFExecutor mainThreadExecutor] withBlock:^id(BFTask *task) {
if (task.result) {
AWSS3TransferManagerDownloadOutput *downloadOutput = task.result;
self.fetchedImage = [UIImage imageWithContentsOfFile:downloadingFilePath];
} else if (task.error) {
NSLog(@"Error: %@", task.error);
}
}];https://stackoverflow.com/questions/28552553
复制相似问题