Created
January 27, 2014 10:08
-
Star
(114)
You must be signed in to star a gist -
Fork
(20)
You must be signed in to fork a gist
-
-
Save homam/8646090 to your computer and use it in GitHub Desktop.
How to upload files to AWS S3 with NodeJS SDK
This file contains 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
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.'); | |
}); | |
}); |
How can I create and get s3 bucket id?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
By far the best simple and straightforward code/implementation and brief explanation I've found. Been stuck on this for 2-3 days lol Thanks guys - peace and love