title: Getting NSData from an NSURL
body: <p>I am trying to upload a photo from my app into a web service.</p>
  
  <p>The flow I am attempting to create is as follows:</p>
  
  <blockquote>
    <ol>
    <li>User takes photo with camera </li>
    <li>Photo is saved to camera roll under a custom album</li>
    <li>URL of the saved photo is given to my store</li>
    <li>Store attempts to upload the photo to a web service.</li>
    </ol>
  </blockquote>
  
  <p>I am trying to use <code>NSData *data = [NSData dataWithContentsOfURL:[item assetURL]]</code> where item is a model that contains the URL concerned. But this line is not producing a data when I log it even if it produces a URL: <code>"assets-library://asset/asset.PNG?id=28DBC0AC-21FF-4560-A9D6-5F4BCA190BDB&amp;ext=PNG"</code></p>
  
  <p>The code snippets are as follows:</p>
  
  <pre><code>-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
  {
  
      UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
  
  
  
      [self dismissViewControllerAnimated:YES completion:^(void){
  
          [library writeImageToSavedPhotosAlbum:image.CGImage orientation:image.imageOrientation completionBlock:^(NSURL* assetURL, NSError* error) {
  
              BCard *card = [[BCard alloc]init];
  
              //error handling
              if (error!=nil) {
                  NSLog(@"[ERROR] - %@",error);
                  return;
              }
  
              //add the asset to the custom photo album
              [library addAssetURL: assetURL
                           toAlbum:@"Business Cards"
               withCompletionBlock:^(NSError *error) {
                   if (error!=nil) {
                       NSLog(@"Custom Album Error: %@", [error description]);
                   }
               }];
  
              [card setAssetURL:assetURL];
  
              [[BCardStore sharedStore]addToQueue:card];
              int index = [[[BCardStore sharedStore]getQueue]count]-1;
  
              [[BCardStore sharedStore]uploadItemAtIndex:index withProgressBlock:nil withExitBlock:nil];
  
          }];
      }];
  
  
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>-(void)uploadItemAtIndex:(NSUInteger)index withProgressBlock:(progressBlock)pBlock withExitBlock:(exitBlock)eBlock
  {
      BCard *item = [uploadQueue objectAtIndex:index];
      NSURL *url = [NSURL URLWithString:@"http://192.168.0.116:8080"];
      NSData *data = [NSData dataWithContentsOfURL:[item assetURL]];
      AFHTTPClient *httpClient = [[AFHTTPClient alloc]initWithBaseURL:url];
      numberedName = numberedName +1;
      NSString *name = [NSString stringWithFormat:@"%d",numberedName];
  
      NSLog(@"%@",[item assetURL]);
  
  //upload data using AFNetworking here
  }
  </code></pre>
  
  <p>The snippet <code>[library addAssetUrl:NSUrl toAlbum:NSString withCompletionBlock:^(NSError *error)]</code> came from the category I found <a href="http://www.touch-code-magazine.com/ios5-saving-photos-in-custom-photo-album-category-for-download/" rel="nofollow">here</a>.</p>
  
  <p>Am I really getting the right URL here or am I using <code>dataWithContentsOfURL</code> incorrectly?</p>