javascript - fswebcam: getting a dataURI via Node.js -
i have fswebcam running on raspberry pi. using command line, saves jpg images.
i want receive these images in node.js application, , send them on used in browser via datauri.
on node.js, do:
var exec = require('child_process').exec; exec("fswebcam -d /dev/video0 -r 160x120 --no-banner --save '-'", function(err, stdout, stderr) { var imagebase64 = new buffer(stdout).tostring('base64');
i send imagebase64
browser.
in browser, setting received data data uri fails:
image.src = "data:image/jpg;base64," + imagebase64;
doing above data uri created stored jpg created fswebcam (via online generator) works fine.
what not seeing here regarding formats , encodings?
the content-type should probably image/jpeg
, not image/jpg
.
also, new buffer(stdout)
redundant since stdout
buffer, can stdout.tostring('base64')
.
lastly, if it's data bad, can double-check base64-encoded output this webpage or writing stdout
disk , using file
command on ensure it's intact.
Comments
Post a Comment