title: Upload Multiple Images to Server IOS
body: <p>I want to know how to upload multiple images to a server using objective C.
  Here is the code snippet that I am trying to use.</p>
  
  <pre><code>-(void)uploadImage:(NSMutableArray *)image andMessageBO:(MessageBO *)message
  {
      NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@PostImageServlet?",kPostImageUploadWebServiceURL]];
      NSMutableURLRequest *postRequest = [NSMutableURLRequest requestWithURL:url];
  
      [postRequest setHTTPMethod:@"POST"];
      [postRequest setTimeoutInterval:60.0];
      NSString *stringBoundary = @"0xKhTmLbOuNdArY";
      NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",stringBoundary];
      [postRequest addValue:contentType forHTTPHeaderField: @"Content-Type"];
  
      NSData *imageData =UIImagePNGRepresentation(image);
  
  
      NSMutableData *postBody = [[NSMutableData alloc] init];
      [postBody appendData:[[NSString stringWithFormat:@"isFormField=true"]dataUsingEncoding:NSUTF8StringEncoding]];
      [postBody appendData:[[NSString stringWithFormat:@"--%@\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
      [postBody appendData:[[NSString stringWithFormat:@"%@",@"Content-Disposition: form-data; name=\"userid\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
      [postBody appendData:[[NSString stringWithFormat:@"%d",messageBO.messageId] dataUsingEncoding:NSUTF8StringEncoding]];
      [postBody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
      [postBody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"profilepic\"; filename=\"%d_postImage.png\"\r\n",messageBO.messageId] dataUsingEncoding:NSUTF8StringEncoding]];
         for (int i = 0; i &lt; [image count]; i++)
      {
          [postBody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"profilepic\"; filename=\"%d_postImage%d.png\"\r\n",messageBO.messageId,i] dataUsingEncoding:NSUTF8StringEncoding]];
          [postBody appendData:[image objectAtIndex:i]];
      }
      [postBody appendData:[[NSString stringWithFormat:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
  
      [postBody appendData:[NSData dataWithData:imageData]];
      [postBody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
      [postRequest setHTTPBody:postBody];
  
      NSData *returnData = [NSURLConnection sendSynchronousRequest:postRequest returningResponse:nil error:nil];
      NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
      DebugLog(@"IMge:%@",returnString);
  
      //  [self removeOfflineImage:expenseBO];
  
  }
  </code></pre>
  
  <p>Thanks</p>