samedi 1 août 2015

Downloading image form AWS S3 in Objective C

So I'm trying to download a picture from Amazon AWS S3 and I'm using the template code they supply but its not wokring.

NSString *downloadFilePath = [NSTemporaryDirectory() stringByAppendingString:@"download-testImage.jpg"];
NSURL *downloadFileURL = [NSURL fileURLWithPath:downloadFilePath];
AWSS3TransferManagerDownloadRequest *downloadRequest = [AWSS3TransferManagerDownloadRequest new];

downloadRequest.bucket = @"tempBucketName"; //changed name for security reasons
downloadRequest.key = @"testImage.jpg";
downloadRequest.downloadingFileURL = downloadFileURL;
NSLog(@"About to start");
// Download the file.
[[self.transferManager download:downloadRequest] continueWithExecutor:[AWSExecutor mainThreadExecutor] withBlock:^id(AWSTask *task) {
    NSLog(@"Started task");
   if (task.error){
       NSLog(@"In if statement");
       if ([task.error.domain isEqualToString:AWSS3TransferManagerErrorDomain]) {
           switch (task.error.code) {
               case AWSS3TransferManagerErrorCancelled:
               case AWSS3TransferManagerErrorPaused:
                   break;

               default:
                   NSLog(@"Error: %@", task.error);
                   break;
           }
       } else {
           // Unknown error.
           NSLog(@"Error: %@", task.error);
       }
   }
   if (task.result) {
       AWSS3TransferManagerDownloadOutput *downloadOutput = task.result;
       //File downloaded successfully.
       NSLog(@"success");
   }
   return nil;
}];
cell.postImage.image = [UIImage imageWithContentsOfFile:downloadFilePath];
NSLog(@"%f", [UIImage imageWithContentsOfFile:downloadFilePath].size.width);

The only thing that is being printed is "About to start" "Done" and in the end, its printing 0.0 for the image size. I added those NSLogs to help you guys pinpoint my problem, how can i fix this?




Aucun commentaire:

Enregistrer un commentaire