Skip to content

Instantly share code, notes, and snippets.

@joedotjs
Last active November 21, 2016 21:58
Show Gist options
  • Save joedotjs/16f2f3846497d457dfb6 to your computer and use it in GitHub Desktop.
Save joedotjs/16f2f3846497d457dfb6 to your computer and use it in GitHub Desktop.
// 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);
});
});
// 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