Skip to content

Instantly share code, notes, and snippets.

@shino shino/node_put.js
Last active Jan 14, 2016

What would you like to do?
"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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.