Created
May 22, 2018 15:54
-
-
Save minhoyooDEV/222ea05b55c4966a4fd7a4136742253c to your computer and use it in GitHub Desktop.
Revisions
-
minhoyooDEV created this gist
May 22, 2018 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,53 @@ //https://gist.github.com/kethinov/6658166 var AWS = require('aws-sdk'), fs = require('fs'), path = require('path'); // For dev purposes only AWS.config.update({accessKeyId: '.', secretAccessKey: '..'}); // Read in the file, convert it to base64, store to S3 //https://gist.github.com/kethinov/6658166 console.log('====read directory==='); var walkSync = function (dir, filelist) { var fs = fs || require('fs'), files = fs.readdirSync(dir); filelist = filelist || []; files.forEach(function (file) { if (file !== 'node_modules' && file !== '.idea') { if (fs.statSync(dir + '/' + file).isDirectory()) { filelist = walkSync(dir + '/' + file, filelist); } else { filelist.push(`${dir}/${file}`); } } }); return filelist; }; var fileList = [] walkSync(process.argv[2], fileList) console.log(fileList) fileList.forEach((file) => { fs.readFile(file, (err, data) => { if (err) { throw err; } var base64data = new Buffer(data, 'binary'); console.log(file, base64data) var s3 = new AWS.S3(); s3.putObject({ Bucket: 'minho-bucket', Key: file.slice(2), Body: base64data, ACL: 'public-read' },function (resp) { console.log(arguments); console.log('Successfully uploaded package.'); }); }) });