Skip to content

Instantly share code, notes, and snippets.

@marksilvis
Created October 6, 2017 02:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save marksilvis/67bca60050004c967f0e48407bc6876a to your computer and use it in GitHub Desktop.
Save marksilvis/67bca60050004c967f0e48407bc6876a to your computer and use it in GitHub Desktop.
Node.js upload to AWS S3
// requires AWS SDK
var AWS = require('aws-sdk')
, fs = require('fs');
var s3 = new AWS.S3({
apiVersion: '2006-03-01',
accessKeyId: 'AccessKey',
secretAccessKey: 'SecretKey',
region: 'region'
});
fs.readFile('filename.jpg', function(err, data) {
var params = {
Bucket: 'bucket-name',
Key: 'bucket/directory',
Body: data,
ContentType: 'image/jpg'
};
s3.putObject(params, function(err, res) {
if (err) {
console.log('error');
console.log(err);
} else {
console.log('success');
console.log(res);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment