mirror of
https://github.com/cnodejs/nodeclub.git
synced 2025-12-08 19:55:55 +00:00
25 lines
634 B
JavaScript
25 lines
634 B
JavaScript
var config = require('../config');
|
|
var utility = require('utility');
|
|
var path = require('path');
|
|
var fs = require('fs');
|
|
|
|
exports.upload = function (file, options, callback) {
|
|
var filename = options.filename;
|
|
|
|
var newFilename = utility.md5(filename + String((new Date()).getTime())) +
|
|
path.extname(filename);
|
|
|
|
var upload_path = config.upload.path;
|
|
var base_url = config.upload.url;
|
|
var filePath = path.join(upload_path, newFilename);
|
|
var fileUrl = base_url + newFilename;
|
|
|
|
file.on('end', function () {
|
|
callback(null, {
|
|
url: fileUrl,
|
|
});
|
|
});
|
|
|
|
file.pipe(fs.createWriteStream(filePath));
|
|
};
|