2013-10-21 80 views
1

我試圖建立一個web gui的canon eos 7d使用node.js(0.10.20),libgphoto2(2.5.2。)和gphoto2模塊的節點在樹莓派(最新raspbian)。node.js/gphoto2 - 如何保存文件(jpg)

除了保存節點中的文件之外,一切似乎都正常。

IM使用下面的代碼片段:

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); 
    }); 
}); 

創建的文件無法讀取/不是有效的JPG圖像使用libgphoto的CLI工具

創建一個有效的圖像:

[email protected] /srv/node/eos $ gphoto2 --capture-image-and-download 

所以我假設錯誤是在節點代碼中的某處保存數據

如何將節點中的數據正確保存爲.jpg文件?

+0

的問題似乎是與節點gphoto2模塊。有關https://github.com/lwille/node-gphoto2/issues/29的更多詳情 – zn4ke

回答

0

我正在處理非常相似的事情。 我似乎記得需要向指定從攝像機的數據是二進制的,是這樣的:

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){} 
      ); 
    }); 
}); 

拍我的電子郵件,如果你想進行合作。

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