felixge/node-formidable — Issue #108: express upload hanging
Author: joshrtay
Created: 2011-11-19 22:51:06+00:00
State: open

Tried the example upload.js and it worked fine. Then I created a very similar test with express and it hangs on upload. Any ideas?

express@2.5.1 ../node_modules/express
── mime@1.2.4
── qs@0.3.2
── mkdirp@0.0.7
── connect@1.8.0

formidable@1.0.7 ../node_modules/formidable

var express = require('express')
, formidable = require('formidable')
, http = require('http')
, util = require('util')
, server;

var app = express.createServer();

app.configure(function() {
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
});

var TEST_TMP = './';

app.post('/upload', function(req,res) {
var form = new formidable.IncomingForm(),
files = [],
fields = [];

form.uploadDir = TEST_TMP;

form
.on('field', function(field, value) {
console.log(field, value);
fields.push([field, value]);
})
.on('file', function(field, file) {
console.log(field, file);
files.push([field, file]);
})
.on('end', function() {
console.log('-> upload done');
res.writeHead(200, {'content-type': 'text/plain'});
res.write('received fields:\n\n '+util.inspect(fields));
res.write('\n\n');
res.end('received files:\n\n '+util.inspect(files));
});
form.parse(req);
})

app.get('/',function(req,res) {
res.send(
'

'+
'
'+
'
'+
''+
'

'
);
});