I’m having trouble sending an UIImage object to my REST web service
that only accepts JSON as input.
I have my object mappings all set and it works to generate the JSON
just fine until it gets to any UIImages.
I read this page about loading the image in separately:
https://github.com/RestKit/RestKit/wiki/Attach-a-File-to-an-RKObjectLoader
but this always changes the content-type from application/json to
application/xxx-form-url-encoded (or whatever it is).
So what is the best way to accomplish this without using RKParams?
I found another link here: https://groups.google.com/forum/#!msg/restkit/QcTPucXXn4o/41IcKDCeoGAJ that talked about an earlier version of
RestKit where you could use propertiesForSerialization from the
RKObjectMappable protocol but that protocol and method no longer seem
to be available in 0.10.0.
Is there some way in the new version that will allow you to replace
the contents of the UIImage with base64 encoded data (therefore JSON
safe) before trying to serialize it?
Or are there any other solutions? Any help appreciated. Thanks
I’ve done this with RestKit by saving to an “imageData” property and encoding the image in base64.
This isn’t great for CoreData, though, so instead I wrote it so that when getting images from the server (encoded in base64), it saves the image to disk and then stores the path in Core Data instead. Then when pushing the image to the server, it finds the file on the disk, encodes to base64, and then includes that in the JSON.
It’s not a perfect method, but if you’re not sending images back and forth a lot it works pretty well.