2

Im trying to build a web gui for a canon eos 7d using node.js (0.10.20), libgphoto2 (2.5.2.) and gphoto2 module for node on a Raspberry Pi (latest raspbian).

Everything seems to work fine except for saving the files in node.

im using the following code snippet:

app.get('/shoot', function(req, res){
    camera.takePicture({download:true}, function(er, data){

        res.header('Content-Type', 'image/jpeg');
        res.send(data);

        fs.writeFile("public/images/sampleImg.jpg", data);
    });
});

The file created is unreadable/not a valid jpg image

using the cli tool for libgphoto creates a valid image:

pi@raspi /srv/node/eos $ gphoto2 --capture-image-and-download

so i assume the error is somewhere in the node-code for saving data

how would i properly save the data in node to a .jpg file?

1

1 Answer 1

0

I am working on something very similar. I seem to remember needing to specify that the data from the camera was binary, something like:

app.get('/shoot', function(req, res){
    camera.takePicture({download:true}, function(er, data){
        res.header('Content-Type', 'image/jpeg');
        res.send(new Buffer(data, 'binary'));
        fs.writeFile(
            "public/images/sampleImg.jpg",
            new Buffer(data, 'binary'),
            function (err){}
            );
    });
});

Shoot me an email if you want to collaborate.

http://tonyspiro.com/uploading-and-resizing-an-image-using-node-js/ http://lists.basho.com/pipermail/riak-users_lists.basho.com/2011-May/004270.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.