title: Upload Image and String Using MultipartAPI
body: <p>i want to upload the image and string using multipartform data
  Here is my code,</p>
  
  <pre><code> +(void)UploadImageWithAlldetails:(NSDictionary *)string imageresource:(NSData *)imageResource andCompletion:(GFWebServiceHandler)completion
   {
   NSString *createNoteUrl=[NSString stringWithFormat:@"%@/%@",BASE_URL,API_TO_UPLOAD_IMAGE];
  
  NSData *jsonData = [NSJSONSerialization dataWithJSONObject: string
                                                     options:0
                                                       error:nil];
  NSString *jsonString =[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
  NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:createNoteUrl]];
  [request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
  [request setHTTPShouldHandleCookies:NO];
  [request setTimeoutInterval:60];
  [request setHTTPMethod:@"POST"];
  [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
  
  
  NSString *boundary = @"unique-consistent-string";
  //set conteent type in HTTP header
  
  NSString *contentType = [NSString stringWithFormat:@"multipart/form-data;boundary=%@",boundary];
  //[request setValue:contentType forHTTPHeaderField:@"Content-Type"];
  [request addValue:contentType forHTTPHeaderField:@"Content_Type"];
  
  NSMutableData *body =[NSMutableData data];
  
  [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary]dataUsingEncoding:NSUTF8StringEncoding]];
  
  
  [body appendData:[[NSString stringWithFormat:@"Content-Disposition : form-data; name = %@\r\n\r\n",@"userDetails"] dataUsingEncoding:NSUTF8StringEncoding]];
  [body appendData:[[NSString stringWithFormat:@"Content-Type :application/octet-stream\r\n\r\n"]dataUsingEncoding:NSUTF8StringEncoding]];
  
  [body appendData:[[NSString stringWithFormat:@"%@\r\n",jsonString]
              dataUsingEncoding:NSUTF8StringEncoding]];
  
  
  //image data
  
  if (imageResource) {
  
  
      [body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
      [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=%@; filename=imageName.png\r\n", @"userImage"] dataUsingEncoding:NSUTF8StringEncoding]];
      [body appendData:[@"Content-Type: image/jpeg\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
  
  
  
  [body appendData:[NSData dataWithData:imageResource]];
  [body appendData:[[NSString stringWithFormat:@"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
  }
  
  [body appendData:[[NSString stringWithFormat:@"--%@--\r\n",boundary ] dataUsingEncoding:NSUTF8StringEncoding]];
  
  // set the content-length
  NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[body length]];
  [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
  
  [request setHTTPBody:body];
  
  
  
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue currentQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
      if(data.length &gt; 0)
      {
          //success
          NSLog(@"%@",response);
  
          NSString *stringFromData = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
  
          NSLog(@"%@",stringFromData);
  
  
      }
  }];
  
  }
  </code></pre>
  
  <p>i have implemented the above code, i am getting json data from server and i have nslog that ,it shows like,res-type :error,msg:error occured while uploading .</p>
  
  <p>Please anyone help me ,to do this ,
  Thanks in Advance !!!</p>