-
-
Save gkze/28183d9177eae6ba0a220dfdeee271f2 to your computer and use it in GitHub Desktop.
AWS-SDK S3 upload
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
// 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