-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_formidable.js
More file actions
43 lines (37 loc) · 1.33 KB
/
Copy pathtest_formidable.js
File metadata and controls
43 lines (37 loc) · 1.33 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
33
34
35
36
37
38
39
40
41
42
43
var formidable = require('formidable'),
http = require('http'),
util = require('util');
http.createServer(function(req, res) {
if (req.url == '/upload' && req.method.toLowerCase() == 'post') {
// parse a file upload
var form = new formidable.IncomingForm();
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}));
});
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(8080);
// received upload:
// { fields: { title: 'Hello World' },
// files:
// { upload:
// { size: 1558,
// path: '/tmp/1c747974a27a6292743669e91f29350b',
// name: 'us-flag.png',
// type: 'image/png',
// lastModifiedDate: Tue, 21 Jun 2011 07:02:41 GMT,
// _writeStream: [Object],
// length: [Getter],
// filename: [Getter],
// mime: [Getter] } } }