Last active
November 21, 2016 21:58
-
-
Save joedotjs/16f2f3846497d457dfb6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Running on your computer. | |
var express = require('express'); | |
var http = require('http'); | |
var fs = require('fs'); | |
var server = http.createServer(); | |
var app = express(); | |
server.on('request', app); | |
server.listen(3001, function () { | |
console.log('Server on.'); | |
}); | |
app.post('/upload-pic', function (req, res, next) { | |
console.log('Request received'); | |
var imageData = new Buffer(0); | |
req.on('data', function (chunk) { | |
imageData = Buffer.concat([imageData, chunk]); | |
}); | |
req.on('end', function () { | |
// Full image ready. | |
fs.writeFile('./'+ Date.now().toString() + '.jpg', imageData); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Running on tessel. | |
var http = require('http'); | |
var av = require('tessel-av'); | |
var camera = new av.Camera(); | |
var takePicture = camera.capture(); | |
takePicture.on('data', function (image) { | |
var request = http.request({ | |
hostname: '192.168.1.23', // Where your other process is running | |
port: 3001, | |
path: '/upload-pic', | |
method: 'POST', | |
headers: { | |
'Content-Type': 'image/jpg', | |
'Content-Length': image.length | |
} | |
}); | |
request.write(image); | |
}); | |
takePicture.on('error', function (err) { | |
console.error(err); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment