How to PUT binary data with REST?
Published February 25th, 2008 in RESTBase64 in XML? Multi-mime? See the question, add a comment if you have an answer, the Google results are not very satisfying. Someone clearly solved the problem. But all REST discussions I’ve found do not adress the problem. Even the “RESTful Web Services” bible is mostly silent on the topic (And I don’t want to declare the binary object a resource and PUT binary data into it).
As co-author of the “bible” I respectfully ask you to reconsider “declare the binary object a resource and PUT binary data into it.” Look at what AtomPub does (specifically, look at pages 279-280 of RWS; I don’t like the way RFC 5023 explains it). An AtomPub member can have two representations: an Atom entry containing metadata, and a binary document containing data. They’re different representations of a single resource, served from different URLs.
The fact that you need two media types is usually a sign that you’ve either got two resources or two different representations of a resource. If this doesn’t work for whatever reason, I’d probably go with MIME multipart.
Base64 encoded and embedded as a CDATA block is what I’m using for an app right now… It’s not for REST web access though.
Thanks, that’s what I currently do with REST, doesn’t look nice though. Not sure how it scales.
@Leonard: Thanks for your reply. Yes, a POST would do as well instead of a POST and PUT.
I wasn’t clear though, I have the need to add several images to one resource (e.g. different sized images or different quality). Use a POST and several PUTs? How do I add meta information like the file name, people in the picture etc which should go with the pictures?