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?

Matteo
  • 37,680
  • 11
  • 100
  • 115
zn4ke
  • 21
  • 2
  • the problem seems to be with the node gphoto2 module. more details on https://github.com/lwille/node-gphoto2/issues/29 – zn4ke Oct 21 '13 at 15:31

1 Answers1

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

David Cary
  • 5,250
  • 6
  • 53
  • 66