I'm performing a patchObject call using the following, based on examples (there are very few) I found:
[[RKObjectManager sharedManager] patchObject:user path:@"profile" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *result) {
// saving data locally and continuing...
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"Failed with error: %@", [error localizedDescription]);
}];
... but I need also to pass an image. The usual way of adding an image parameter is to add it to a request and then assign this to the operation to be used, i.e.:
request = [[RKObjectManager sharedManager] multipartFormRequestWithObject:user
method:RKRequestMethodPOST
path:@"profile"
parameters:nil
constructingBodyWithBlock:^(id<AFRKMultipartFormData> formData) {
[formData appendPartWithFileData:UIImagePNGRepresentation(self.photoImageView.image)
name:@"user[avatar]"
fileName:@"photo.png"
mimeType:@"image/png"];
}];
RKManagedObjectRequestOperation *operation = [[RKManagedObjectRequestOperation alloc] initWithRequest:request responseDescriptors:@[responseDescriptor, errorDescriptor]];
operation.managedObjectContext = [RKManagedObjectStore defaultStore].mainQueueManagedObjectContext;
operation.managedObjectCache = [RKManagedObjectStore defaultStore].managedObjectCache;
// etc...
As the patchObject method doesn't give me the ability to define the operation (or, therefore, request) being used, I can't see how I can add the image data to the API call.
Previously available methods allowing the image to be defined within a block when performing the patchObject don't seem to exist in RestKit anymore.
Any thoughts? I'd be grateful for any tips on how to do this!
Thanks in advance.