-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.js
33 lines (27 loc) · 891 Bytes
/
upload.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
var express = require('express')
, multiparty = require('multiparty')
, cors = require('cors')
, util = require('util')
, app = express();
app.use(cors());
process.on('uncaughtException', function (err) {
console.log(err);
});
app.get('/', cors(), function(req, res, next){
res.json({msg: 'This is CORS-enabled for all origins!'});
});
app.post('/upload', cors(), function(req, res, next){
var form = new multiparty.Form();
form.parse(req, function(err, fields, files) {
res.writeHead(200, {'content-type': 'text/plain'});
res.write('received upload:\n\n');
res.end(util.inspect({fields: fields, files: files}));
});
form.on('file', function(name,file) {
console.log(file);
console.log(name);
});
});
app.listen(4000, function(){
console.log('CORS-enabled web server listening on port 4000');
});