forked from mycolorway/simple-uploader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
30 lines (23 loc) · 756 Bytes
/
server.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
// nodejs server for upload testing
var express = require('express');
var path = require('path')
var fs = require('fs');
var app = express();
fs.mkdir('./uploads', 0777, function() {
});
app.use(express.bodyParser({uploadDir:'./uploads'}));
app.post('/upload', function(req, res) {
var tmp_path = req.files.upload_file.path;
var target_path = path.resolve('./uploads', req.files.upload_file.name);
fs.rename(tmp_path, target_path, function(err) {
if (err) throw err;
fs.unlink(tmp_path, function() {
if (err) throw err;
res.send({
success: true,
file_path: 'assets/images/' + req.files.upload_file.name
});
});
});
});
module.exports = app;