title: upload picked image in objective-c
body: <p>I'm new to objective-c. I need the image picked in the first function to be uploaded in the second one:</p>
  
  <pre><code>- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
  
      UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
      self.imageView.image = chosenImage;
  
      [picker dismissViewControllerAnimated:YES completion:NULL];
  
  }
  
  - (IBAction)uploadPic:(UIButton *)sender {
      // COnvert Image to NSData
      NSData *dataImage = UIImageJPEGRepresentation([UIImage imageNamed:@"yourImage"], 1.0f);
  
  //added after editing
  
      // set your URL Where to Upload Image
      NSString *urlString = @"http://url";
  
      // set your Image Name
      NSString *filename = @"uploaded_file";
  
      // Create 'POST' MutableRequest with Data and Other Image Attachment.
      NSMutableURLRequest* request= [[NSMutableURLRequest alloc] init];
      [request setURL:[NSURL URLWithString:urlString]];
      [request setHTTPMethod:@"POST"];
      NSString *boundary = @"---------------------------14737809831466499882746641449";
      NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
      [request addValue:contentType forHTTPHeaderField: @"Content-Type"];
      NSMutableData *postbody = [NSMutableData data];
      [postbody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
      [postbody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"userfile\"; filename=\"%@.jpg\"\r\n", filename] dataUsingEncoding:NSUTF8StringEncoding]];
      [postbody appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
      [postbody appendData:[NSData dataWithData:dataImage]];
      [postbody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
      [request setHTTPBody:postbody];
  
      // Get Response of Your Request
      NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
      NSString *responseString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
      NSLog(@"Response  %@",responseString);
  //end editing
      }
  </code></pre>
  
  <p>The added code, in btween editing comments, is the one that I use to upload the image</p>