Skip to content

Instantly share code, notes, and snippets.

@gkze
Forked from james-fourth/s3_addToBucket.js
Last active December 14, 2019 22:11
Show Gist options
  • Save gkze/28183d9177eae6ba0a220dfdeee271f2 to your computer and use it in GitHub Desktop.
Save gkze/28183d9177eae6ba0a220dfdeee271f2 to your computer and use it in GitHub Desktop.
AWS-SDK S3 upload
// Load the AWS SDK, fs and path modules for Node.js
var AWS = require("aws-sdk");
var fs = require("fs");
// Set the region
AWS.config.update({region: "us-west-1"})
// Create S3 service object
const s3 = new AWS.S3({apiVersion: "2006-03-01"});
function upload(bucketName, fileName, fileContent, callback) {
s3.upload({
Bucket: bucketName,
Key: fileName,
Body: fileContent,
}, function(err, data) {
if (err) {
console.log(err);
} else {
callback(data.Location);
}
});
}
const stream = fs.createReadStream(process.argv[3]);
console.log(process.argv);
upload(process.argv[2], process.argv[3], stream, function(loc) { console.log(loc) })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment