Skip to content

Instantly share code, notes, and snippets.

@d-smith
Created October 31, 2014 15:40
Show Gist options
  • Save d-smith/c11227978607efaf889d to your computer and use it in GitHub Desktop.
Save d-smith/c11227978607efaf889d to your computer and use it in GitHub Desktop.
Upload to S3
"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