Created
October 31, 2014 15:40
-
-
Save d-smith/c11227978607efaf889d to your computer and use it in GitHub Desktop.
Upload to S3
This file contains hidden or 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
"use strict"; | |
var AWS = require('aws-sdk'); | |
var fs = require('fs'); | |
AWS.config.update({region: 'us-east-1'}); | |
AWS.config.loadFromPath('../config.json'); | |
var httpProxy = process.env.http_proxy; | |
if(httpProxy !== null) { | |
console.log('set http proxy to ' + httpProxy); | |
AWS.config.update({ | |
httpOptions: { | |
proxy: httpProxy | |
} | |
}); | |
} else { | |
console.log("No proxy settings found"); | |
} | |
fs.readFile("./image.jpg", function(error, data) { | |
if(error) { | |
return console.log("error reading file: " + error); | |
} | |
var s3 = new AWS.S3(); | |
var putParams = { | |
Bucket: 'xt-iot-bucket', | |
Key: 'foo', | |
Body: data | |
}; | |
console.log('put object'); | |
s3.putObject(putParams, function(err, data) { | |
if(err) { | |
console.log('error putting object'); | |
console.log(err); | |
} else { | |
console.log(data); | |
} | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment