Last active
November 30, 2017 16:36
-
-
Save burkel24/a496c412e1fe9f3470afb76d24e8dc57 to your computer and use it in GitHub Desktop.
A tiny command line tool to upload a file 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
// yarn add s3 | |
const s3 = require('s3'); | |
const helpPrases = ['help', '?', '-help', '--help']; | |
if (!process.argv[2] || helpPrases.includes(process.argv[2])) { | |
console.log(`USEAGE: node s3.js <path to file> <bucket name> <destination name>`); | |
return; | |
} | |
const client = s3.createClient({ | |
maxAsyncS3: 20, | |
s3RetryCount: 3, | |
s3RetryDelay: 1000, | |
multipartUploadThreshold: 20971520, | |
multipartUploadSize: 15728640, | |
s3Options: { | |
accessKeyId: process.env.AWS_ID, | |
secretAccessKey: process.env.AWS_SECRET | |
}, | |
}); | |
const uploadParams = { | |
localFile: `${__dirname}/${process.argv[2]}`, | |
s3Params: { | |
Bucket: process.argv[3], | |
Key: process.argv[4] | |
} | |
} | |
const uploader = client.uploadFile(uploadParams); | |
uploader.on('error', err => console.error("unable to upload:", err.stack)); | |
uploader.on('progress', () => console.log("progress", uploader.progressMd5Amount, uploader.progressAmount, uploader.progressTotal)); | |
uploader.on('end', () => console.log("done uploading")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment