Last active
January 14, 2016 14:25
-
-
Save shino/ac7d56398557fb936899 to your computer and use it in GitHub Desktop.
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
"use strict"; | |
var fs = require('fs'), AWS = require('aws-sdk'); | |
var config_file = process.argv[2]; | |
// console.log("configuration file:", config_file); | |
var conf = JSON.parse(fs.readFileSync(config_file, 'utf8')); | |
// console.log(conf); | |
var bucket = process.argv[3]; | |
var fileName = process.argv[4]; | |
AWS.config.update( { "accessKeyId": conf.accessKeyId, | |
"secretAccessKey": conf.secretAccessKey, | |
"region": "us-east-1", | |
'httpOptions': {'proxy': conf.proxy}}); | |
var s3 = new AWS.S3(); | |
var globalUnCaughtException = function(err) { | |
console.log("uncaughtException: ", err.stack); | |
}; | |
process.on('uncaughtException', globalUnCaughtException); | |
function uploadFile(s3) { | |
// console.log(s3); | |
var body = fs.createReadStream(fileName); | |
var params = {Bucket: bucket, Key: fileKey, Body: body}; | |
s3.upload(params, function(err, data) { | |
console.log("Upload finished."); | |
console.log("error:", err); | |
console.log("data:", data); | |
}); | |
}; | |
// strip path for s3 | |
var fileKey = fileName.slice(fileName.lastIndexOf("/")+1); | |
console.log("fileKey: " + fileKey); | |
// S3 Upload options | |
uploadFile(s3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment