the blog for developers

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

You can leave a Reply here. Of course, you should follow me on twitter here.

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.

About the author: Stephan Schmidt is head of development at brands4friends. He has more than 15 years of internet technology experience and 10 years experience in agile. He was head of development, consultant and CTO and is a speaker, author and blog writer. He specializes in organizing and optimizing software development helping companies by increasing productivity with lean software development and agile methodologies. Want to know more? All views are only his own.
Leave a reply.

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

What people wrote somewhere else:

Additional comments powered by BackType

Guide to CodeMonkeyism

Over the last 4 years I wrote many articles on this blog. To make it easier for you to find the relevant ones, I've organized them into topics.

Top 10

6 reasons why my VC funded startup did fail

Go Ahead: Next Generation Java Programming Style

Java Interview questions: Write a String Reverser

The dark side of NoSQL

7 Bad Signs not to Work for a Software Company or Startup

Is Java dead?

Scala vs. Clojure

Never, never, never use String in Java

No future for functional programming in 2008 – Scala, F# and Nu

Clojure vs Scala, Part 2

Java Developer

Is Java Dead?

Go Ahead: Next Generation Java Programming Style

Be careful with magical code

All variables in Java must be final

Never, never, never use String in Java

Bending Java: More readable code with methods that do nothing?

NoSQL Guy

NoSQL: The Dawn of Polyglot Persistence

The dark side of NoSQL

Essential storage tradeoff: Simple Reads vs. Simple Writes

Sharding destroys the goals of your relational database

The unholy legacy of databases

Startup/CTO

Development Dream Teams

6 reasons why my VC funded startup did fail

American vs. European style of Software Development

12 Things to Reduce Your Lead Time and Time to Market

The high cost of overhead when working in parallel

Essential storage tradeoff: Simple Reads vs. Simple Writes

Job Seeker

Another Good (Java) Interview Question

7 Bad Signs not to Work for a Software Company or Startup

Java Interview questions: Write a String Reverser (and use Recursion!)

Java Interview questions: Multiple Inheritance

As a Manager: What I value in developers

Top 10 Tips (+1) to Get a Pay Raise

Agilist

What Developers Need to Know About Agile

5 Practices Better to Change in Your Scrum Implementation

Scrum is not about engineering practices

ScrumMaster and ZenMaster: The joke of certification

What is Trans-Scrum?