Skip to content

Instantly share code, notes, and snippets.

@blakewatters
Created July 29, 2011 16:18
Show Gist options
  • Save blakewatters/1114150 to your computer and use it in GitHub Desktop.
Save blakewatters/1114150 to your computer and use it in GitHub Desktop.
Attach an Image to an Object Loader
[[RKObjectManager sharedManager] postObject:contact delegate:self block:^(RKObjectLoader* loader) {
RKObjectMapping* serializationMapping = [[[RKObjectManager sharedManager] mappingProvider] serializationMappingForClass:[Contact class]];
NSError* error = nil;
NSDictionary* dictionary = [[RKObjectSerializer serializerWithObject:contact mapping:serializationMapping] serializedObject:&error];
RKParams* params = [RKParams paramsWithDictionary:dictionary];
[params setData:[contact avatarImageData] MIMEType:@"image/png" forParam:@"avatar_image"];
loader.params = params;
}];
@dickbrouwer
Copy link

NSDictionary* dictionary = [[[RKObjectSerializer serializerWithObject:contact] mapping:serializationMapping] serializedObject:&error];

Should be

NSDictionary* dictionary = [[RKObjectSerializer serializerWithObject:contact mapping:serializationMapping] serializedObject:&error];

@dickbrouwer
Copy link

forParams:@"avatar_image"
should read
forParam:@"avatar_image"
(without the s)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment