1

我希望在用户注册我的应用程序时将他们的个人资料图片上传到我的 S3 存储桶。

我需要先从 facebook 下载图片,还是可以将外部 url 传递给 AWSS3TransferManager?Preferable 我当然希望不必先将图片下载到客户端的设备,然后才上传到 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];}
4

0 回答 0