You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nodebb/src/file.js

33 lines
703 B
JavaScript

11 years ago
"use strict";
var fs = require('fs'),
nconf = require('nconf'),
path = require('path'),
winston = require('winston');
var file = {};
10 years ago
file.saveFileToLocal = function(filename, folder, tempPath, callback) {
10 years ago
var uploadPath = path.join(nconf.get('base_dir'), nconf.get('upload_path'), folder, 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') + folder + '/' + filename
});
});
os.on('error', function (err) {
winston.error(err.message);
callback(err);
});
is.pipe(os);
11 years ago
};
module.exports = file;