Skip to content

Instantly share code, notes, and snippets.

@tako2
Created November 15, 2015 06:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tako2/421a3df53f1a855ecdb0 to your computer and use it in GitHub Desktop.
Save tako2/421a3df53f1a855ecdb0 to your computer and use it in GitHub Desktop.
node.js script for getting image file from THETA S.
var request = require('request');
var fs = require('fs');
if (process.argv.length < 3) {
console.log('node get_image.js [Filename]');
console.log("\tFilename: Image Filename such as R0010010.JPG");
return;
}
var file_uri = process.argv[2];
console.log('Get Image from "100RICOH/%s"', file_uri);
var options = {
uri: 'http://192.168.1.1/osc/commands/execute',
headers: { 'Content-Type': 'application/json' },
json: true,
keepAlive: false,
encoding: null, // IMPORTANT
body: { "name": "camera.getImage",
"parameters": { "fileUri": "100RICOH/" + file_uri }
}
};
request.post(options, function(err, res, body) {
if (err) {
console.log(err);
return;
}
if (res.statusCode == 200) {
// console.log(res.headers);
console.log('Save Image to %s', file_uri);
fs.writeFile(file_uri, body, encoding="binary");
} else {
console.log('Connection Failure... (%d)', res.statusCode);
// console.log(body);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment