-
-
Save ss2k/629bd2b2cf9d9af4b437 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
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); | |
}); | |
}); | |
}; |
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
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