Skip to content

Instantly share code, notes, and snippets.

@jaypsan
Last active November 16, 2023 20:52
Show Gist options
  • Save jaypsan/efadf83871b751b031ebed288cdf0408 to your computer and use it in GitHub Desktop.
Save jaypsan/efadf83871b751b031ebed288cdf0408 to your computer and use it in GitHub Desktop.
Get snapshot from IP camera with Onvif protocol and send through express http response
function handler(req, res) {
const {hostname, username, password} = req.body
new Cam({
hostname
, username
, password
}, function(err){
this.getSnapshotUri({protocol:'RTSP'}, function (err, stream){
// Make GET request to snapshot uri from câmera
http.get(stream.uri, {auth: `${username}:${password}`}, (httpResponse) => {
// Array for the httpResponse buffers
var buffers = []
// When receive data, push to array.
// When finished, send image to res
httpResponse.on('data', (data) => {
buffers.push(data)
}).on('end', () => {
res.contentType('image/jpeg')
res.send(new Buffer.concat(buffers))
})
})
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment