Created
October 6, 2017 02:01
-
-
Save marksilvis/67bca60050004c967f0e48407bc6876a to your computer and use it in GitHub Desktop.
Node.js upload to AWS S3
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
// 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