-
Notifications
You must be signed in to change notification settings - Fork 0
/
uploader.js
40 lines (37 loc) · 1002 Bytes
/
uploader.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var fs = require("fs");
var async = require('async');
var cmd = require('node-cmd');
var mkdirp = require('mkdirp')
exports.save = function (req, res) {
const video = req.files[0]
// check file
// write file
async.waterfall([
function (callback) {
fs.readFile(video.path, (error, result) => {
if (error) {
console.log('ReadError:', error)
} else {
return callback(null, result)
}
})
},
function (result, callback) {
const videoStoragePath = __dirname + '/videos/'
// create directory if does not exists
mkdirp(videoStoragePath, function (error) {
if (error) {
console.log('MakeDirError:', error)
}
fs.writeFile(videoStoragePath + video.originalname, result, (error) => {
if (error) {
console.log('WriteError:', error)
} else {
return callback(null, 'success')
}
})
})
}
])
res.send('success')
}