JP H
unread,May 14, 2012, 7:36:52 PM5/14/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to RestKit
Hello,
I am having an issue that could have multiple solutions, but could not
find one yet.
I have a class defined as:
@interface MyClass:NSObject
@property(nonatomic,strong) NSString *myProperty;
@property(nonatomic,strong) NSMutableArray *myArray;
- I am doing a POST such as:
[[RKObjectManager sharedManager] postObject:myObject
usingBlock:^(RKObjectLoader *loader){
loader.delegate=delegate;
}
POST is successful, including the values in myArray, which are sent
properly. The logs show encoding is done properly for this array
(myArray[]=value1&myArray[]=value2)
- Now I want to upload an image as part of this
So I transform my post call to:
[[RKObjectManager sharedManager] postObject:myObject
usingBlock:^(RKObjectLoader *loader){
loader.delegate=delegate;
RKObjectMapping* serializationMapping = [[[RKObjectManager
sharedManager] mappingProvider] serializationMappingForClass:[MyClass
class]];
NSError* error = nil;
NSDictionary* dictionary = [[RKObjectSerializer
serializerWithObject:self.onboardingUser mapping:serializationMapping]
serializedObject:&error];
RKParams* params = [RKParams paramsWithDictionary:dictionary];
//picture upload
if(self.imageData){
RKParamsAttachment* attachment =[params
setData:self.onboardingUser.imageData MIMEType:@"image/jpg"
forParam:@"image"];
attachment.fileName=@"image.jpg";
}
loader.params=params;
}
The uploading of the picture works fine if the array attribute is
empty.
However, with values in myArray, my post is rejected because the
encoding is not done properly.
As part of the serialization, myArray becomes a string that looks
something like this:
(\n value1,\n value2)
And is sent as a single value for the attribute myArray (myArray=
(\n value1,\n value2) )
So, possible answers that could help me:
- Obviously, is it possible to not have the serialization do that?
- Is it possible to maybe to attach the picture in another method?
I have tried doing that in - (void)objectLoader:(RKObjectLoader
*)objectLoader didSerializeSourceObject:(id)sourceObject
toSerialization:(inout id<RKRequestSerializable> *)serialization
But was unsuccessful at using the setData:MIMEType:forParam: method
- Is it possible to reconstruct the array element manually if
necessary, that would be ugly, but anything that could work at this
point...
- Other solution I could not think of?