title: Upload A File Into A Server - Objective C/Xcode/Mediawiki
body: <p>I want to upload a <code>UIImage</code> into a server. For this I am using the following lines of code ::</p>
  
  <pre><code>- (void)imagePickerController:(UIImagePickerController *)picker 
      didFinishPickingImage:(UIImage *)image
                editingInfo:(NSDictionary *)editingInfo
  {
  
  
  imageView.image = image;    
  
  NSData *pngData = UIImagePNGRepresentation(imageView.image);
  
  NSString *imageFile = @"image.png";   
  NSString *docDir = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
  NSString *filePath = [docDir stringByAppendingPathComponent:imageFile]; 
  NSString *dataIS=[NSString base64StringFromData:pngData length:[pngData length]];
  [pngData writeToFile:filePath atomically:YES];
  
  
  
  
  
  
  NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
  [request setURL:[NSURL URLWithString:urlString]];
  [request setHTTPMethod:@"POST"];
  
  
  NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"];
  NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
  [request addValue:contentType forHTTPHeaderField: @"Content-Type"];
  
  
  NSMutableData *body = [NSMutableData data];
  [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];    
  [body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"image\"; filename=\"image.png\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
  [body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
  [body appendData:[NSData dataWithData:pngData]];
  [body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
  // setting the body of the post to the reqeust
  [request setHTTPBody:body];
  
  
  NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
  NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
  
  
  [self.parentViewController dismissModalViewControllerAnimated:YES];
  
  }
  </code></pre>
  
  <p>But, I am getting the following error in gdb :: </p>
  
  <p><code>Your request could not be processed. Request could not be handled</code>.</p>
  
  <p>I am also confused over the proper use of <code>urlString</code> i.e. I am doubtful over my correct use of it. </p>
  
  <p>If I however use the following <code>urlString</code>, I am able to upload my image file into the server ::</p>
  
  <pre><code>NSString *urlString = [NSString stringWithFormat:@"http://xxxx.com/mediawiki/api.php?action=upload&amp;filename=image.png&amp;url=%@&amp;token=%@", url, token] ;
  </code></pre>
  
  <p>With reference to the <code>API</code> for <code>mediawiki</code> (http://www.mediawiki.org/wiki/API:Upload), can someone help me to sort it out ?? Thanks and Regards.</p>