Skip to content

Instantly share code, notes, and snippets.

@LukaszWiktor
Forked from homam/AWS_S3_File_Upload.js
Created February 13, 2017 12:17
Show Gist options
  • Save LukaszWiktor/2bbb2b6208f0e7773d6109b1485a47c2 to your computer and use it in GitHub Desktop.
Save LukaszWiktor/2bbb2b6208f0e7773d6109b1485a47c2 to your computer and use it in GitHub Desktop.
How to upload files to AWS S3 with NodeJS SDK
var AWS = require('aws-sdk'),
fs = require('fs');
// For dev purposes only
AWS.config.update({ accessKeyId: '...', secretAccessKey: '...' });
// Read in the file, convert it to base64, store to S3
fs.readFile('del.txt', function (err, data) {
if (err) { throw err; }
var base64data = new Buffer(data, 'binary');
var s3 = new AWS.S3();
s3.client.putObject({
Bucket: 'banners-adxs',
Key: 'del2.txt',
Body: base64data,
ACL: 'public-read'
},function (resp) {
console.log(arguments);
console.log('Successfully uploaded package.');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment