我希望用户在注册我的应用时上传到我的S3存储桶的个人资料图片。
我是否需要先从Facebook下载图片,还是可以将外部网址传递给AWSS3TransferManager?我当然希望不必先将图片下载到客户端的设备中,然后再上传到S3。
//We create the url to the FB Profile Picture
NSString *compURLString = [NSString stringWithFormat:@"https://graph.facebook.com/FACEBOOKID/picture?type=large"];
NSURL *url = [NSURL URLWithString:compURLString];
// We download the FB Profile Picture from Facebook TBD DO WE NEED THIS STEP OR IS IT POSSIBLE TO PASS THE EXTERNAL URL? AND NOT DOWNLOAD THE IMAGE FIRST? https://graph.facebook.com/FACEBOOKID/picture?type=large TO THE AWS UPLOAD MANAGER
NSURLSessionDownloadTask *downloadPhotoTask = [[NSURLSession sharedSession]
downloadTaskWithURL:url completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error) {
UIImage
// NOw that we have the FB Profile Picture, we upload it to S3
AWSS3TransferManager *uploadManager = [AWSS3TransferManager defaultS3TransferManager];
NSString *const S3BucketName = @"DEMO";
//upload the image
AWSS3TransferManagerUploadRequest *uploadRequest = [AWSS3TransferManagerUploadRequest new];
uploadRequest.body = location;
uploadRequest.bucket = S3BucketName;
uploadRequest.key = [NSString stringWithFormat:@"@%.jpg", facebookID];
uploadRequest.contentType = @"image/jpg";
[[uploadManager upload:uploadRequest] continueWithExecutor:[AWSExecutor mainThreadExecutor]
withBlock:^id(AWSTask *task) {...
}];
[downloadPhotoTask resume];}