Streaming a binary file from riak via node.js to client

Max nash12 at
Sat May 21 06:04:54 EDT 2011

After watching the presentation about how to use node.js with riak, I
built some small application on node.js using the express framework.

In riak files are stored via a PHP frontend but they should be served
via a node.js backend. Anyway, connecting to riak via node.js is not
that hard and sending the response is also rather easy. But it seems,
somewhere the buffer I get via the client.get operation is truncated.
I am using this code:

app.get('/images/', function(req, res){
    riakClient.get('images', 'some.jpg', function(err, image, meta) {
        if (err) {
            throw err;

        res.send(image, {
            'Content-Type': meta.contentType

To test if the image is served, but whenn I access the node.js url,
the browser tells me that the image cannot be displayed as it contains
errors. The filesize of the served image is too small compared to the
original. If I access the url /images/some.jpg directly via rest
interface on the command line, the correct image is returned.

Has anyone experience in how to stream binary data from riak?

Thanks in advance!

More information about the riak-users mailing list