Skip to content

Instantly share code, notes, and snippets.

@ss2k

ss2k/s3.js Secret

Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ss2k/629bd2b2cf9d9af4b437 to your computer and use it in GitHub Desktop.
Save ss2k/629bd2b2cf9d9af4b437 to your computer and use it in GitHub Desktop.
var BUCKET_NAME = "logs";
var LOG_FILE_NAME = "log_file.log";
var LOG_FILE_PATH = "./var/logs/" + LOG_FILE_NAME;
var AWS = require('aws-sdk');
var fs = require('fs');
AWS.config.loadFromPath('./config.json');
exports.uploadLog = function(callback) {
fs.readFile(LOG_FILE_PATH, function(err,data){
if (err) { throw err; }
var s3 = new AWS.S3();
var params = {
Bucket: BUCKET_NAME,
Key: LOG_FILE_NAME,
Body: data,
ACL: 'private'
};
s3.putObject(params, function(err, res) {
if (err) callback(err);
else callback(null, res);
});
});
};
var S3 = require('../lib/s3');
exports.uploadLog = function(req, res) {
S3.uploadFile(function(error, data){
if (error) {
console.log(error);
res.json({ "status": "failure", "error": error });
} else {
res.json({"status": "ok"});
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment