我试图从我的Amazon S3 Bucket(v2)下载图像,但我无法弄明白。我一直从[transferManager download:downloadRequest];
获得null所有帐户详细信息/密钥均已填写。欢迎任何帮助。
-(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;
}
答案 0 :(得分:3)
对于初学者,您滥用AWSS3TransferManagerDownloadRequest
的{{1}}财产。 downloadingFileURL
不应该引用您从中获取的S3位置;相反,它应该引用您将该文件写入的磁盘位置,例如:
downloadingFileURL
该文件下载完成后,将显示在该文件路径中。
要知道你的文件何时准备就绪,我建议你在一个块中执行你的下载请求:
NSString *downloadingFilePath = [NSTemporaryDirectory()stringByAppendingPathComponent:@"hello.png"];
NSURL *downloadingFileURL = [NSURL fileURLWithPath:downloadingFilePath];