-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexampleUploadFile.js
More file actions
executable file
·32 lines (29 loc) · 1.01 KB
/
exampleUploadFile.js
File metadata and controls
executable file
·32 lines (29 loc) · 1.01 KB
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
#!/usr/bin/env node
var multiparty = require('multiparty')
, http = require('http')
, util = require('util')
http.createServer(function(req, res) {
if (req.url === '/upload' && req.method === 'POST') {
var form = new multiparty.Form();
form.parse(req, function(err, fields, files) {
res.writeHead(200, {'content-type': 'text/plain'});
for(f in files.upload){
var uploadedTo=files.upload[f].path;
res.write('received upload ('+uploadedTo+')\n\n');
}
for(f in fields){ res.write('received field('+f+')='+fields[f]+'\n\n'); }
res.write('fields + files =\n\n');
res.end(util.inspect({fields: fields, files: files}));
});
return;
}
// show a file upload form
res.writeHead(200, {'content-type': 'text/html'});
res.end(
'<form action="/upload" enctype="multipart/form-data" method="post">'+
'<input type="text" name="title"><br>'+
'<input type="file" name="upload" multiple="multiple"><br>'+
'<input type="submit" value="Upload">'+
'</form>'
);
}).listen(8002);