Programming is hard by Stephan Schmidt

How to PUT binary data with REST?

Base64 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).

If you liked this post, subscribe to my free full RSS feed.
Filed under: REST

You can share this post!
Do you want to tell others about this article? Use the social bookmark icons to submit this artice to the service of your choice. Thanks.

Get free updates by email

If you did like this article you can get free updates with your RSS reader, you can follow me on Twitter or get free update to new posts by email. Enter your email:

 
About the author: Stephan has been working as a head of development and CTO. He has experiences in different technologies since 20 years including Java, Rails and Python. Stephans main field of interest is maintainablity and productivity in software development. Want to know more? All views are only his own.

Comments

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.

Jason Carreira

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.

stephan

Thanks, that’s what I currently do with REST, doesn’t look nice though. Not sure how it scales.

stephan

@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?

Leave a Reply