From 695891ffd7192a2c92d239950e2db095ce948274 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Thu, 13 Feb 2014 20:43:19 -0500 Subject: [PATCH] added missing file --- src/file.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/file.js diff --git a/src/file.js b/src/file.js new file mode 100644 index 0000000000..46044c3c6b --- /dev/null +++ b/src/file.js @@ -0,0 +1,33 @@ +var fs = require('fs'), + nconf = require('nconf'), + path = require('path'), + winston = require('winston'); + +var file = {}; + +file.saveFileToLocal = function(filename, tempPath, callback) { + + var uploadPath = path.join(nconf.get('base_dir'), nconf.get('upload_path'), filename); + + winston.info('Saving file '+ filename +' to : ' + uploadPath); + + var is = fs.createReadStream(tempPath); + var os = fs.createWriteStream(uploadPath); + + is.on('end', function () { + callback(null, { + url: nconf.get('upload_url') + filename + }); + }); + + os.on('error', function (err) { + winston.error(err.message); + callback(err); + }); + + is.pipe(os); +} + +module.exports = file; + +