title: Restkit MultiForm Post with an Image
body: <h1>Problem</h1>
  
  <p>I've been trying to post to the server with a multiform request that includes an image attachment.  I haven't had trouble getting the image to the server, it is the other information that is not sending correctly.</p>
  
  <h1>Details</h1>
  
  <p>I'm using object mapping to configure several different attributes when receiving objects from the server:</p>
  
  <pre><code>//Using a custom class to map object I receive to
  RKObjectMapping * memoryMapper = [RKObjectMapping mappingForClass:[MemoContent class]];
  [memoryMapper mapAttributes:@"created", @"user", @"participants", @"tags", @"text", @"kind", @"video", @"location", nil];
  [memoryMapper mapKeyPath:@"_id" toAttribute:@"memoryID"];
  
  //MediaMapper handles the data needed for the Image attachments
  RKObjectMapping * mediaMapper = [RKObjectMapping mappingForClass:[MemoMedia class]];
  [mediaMapper mapKeyPath:@"processed" toAttribute:@"processed"];
  [mediaMapper mapKeyPath:@"original" toAttribute:@"original"];
  [mediaMapper mapKeyPath:@"mime" toAttribute:@"mimeType"];
  [memoryMapper mapKeyPath:@"media" toRelationship:@"rawMedia" withMapping:mediaMapper];
  
  //
  [[RKObjectManager sharedManager].mappingProvider setMapping:memoryMapper forKeyPath:@"memories"];
  [RKObjectManager sharedManager].serializationMIMEType = RKMIMETypeFormURLEncoded;
  [RKObjectManager sharedManager].acceptMIMEType = RKMIMETypeJSON;
  </code></pre>
  
  <p>Then, when it comes time to post a photo I update configurations as follows:</p>
  
  <pre><code> RKObjectMapping * memoryMapper = [RKObjectMapping mappingForClass:[MemoContent class]];
  [memoryMapper mapAttributes:@"created", @"participants",  nil];
  [[RKObjectManager sharedManager].mappingProvider setSerializationMapping:memoryMapper forClass:[MemoContent class]];
  [[RKObjectManager sharedManager].mappingProvider setMapping:memoryMapper forKeyPath:@"memory"];
  </code></pre>
  
  <p>Participants are people tagged with the photo.  Here is how I'm posting it, similar to this <a href="https://github.com/RestKit/RestKit/wiki/Attach-a-File-to-an-RKObjectLoader" rel="noreferrer">https://github.com/RestKit/RestKit/wiki/Attach-a-File-to-an-RKObjectLoader</a></p>
  
  <pre><code>   [[RKObjectManager sharedManager] postObject:theMemory usingBlock:^(RKObjectLoader * loader){
  
      RKObjectMapping* serializationMapping = [[[RKObjectManager sharedManager] mappingProvider] serializationMappingForClass:[MemoContent class]];
      NSLog(@"serializationMapping: %@", serializationMapping);
      loader.delegate = APP; //main app delegate posting, updating
      NSError* error = nil;
      RKObjectSerializer * serializer = [[RKObjectSerializer alloc] initWithObject:theMemory mapping:serializationMapping];
      NSDictionary * dictionary = [serializer serializedObject:&amp;error];  
      RKParams * params = [RKParams paramsWithDictionary:dictionary];
      NSData * imageData = UIImagePNGRepresentation(theMemory.photo); //image data
      [params setData:imageData MIMEType:@"image/png" forParam:@"attachment"];
      loader.params = params;
      loader.serializationMIMEType = RKMIMETypeFormURLEncoded;
      }];
  </code></pre>
  
  <p>The server is receiving the image as planned, and actually does receive the 'created' and 'participants' unfortunately it's in a strange format that the server doesn't understand.  It includes line breaks and such <code>participants (\n   19843589323 \n created: \n 3-31-2012 00:00</code>  (something like that, I will update when I have access to the logs.</p>
  
  <p>I will give you any extra info you need. Would offer reputation for it if I had enough to do so ;)</p>