Really need help.
Nodejs cannot receive POST request when enctype="multipart/form-data", browser just hangs.. no response, nothing happens and then timeout (later files could be found in specified folder on server with name of hash string). The code is tested locally, where it works fine.
Request info (from Google Chrome Network Tab)
Headers: Content-Type:multipart/form-data;
Payload: Content-Disposition: form-data; name="file"; filename="1_leaf_music.png"
Responce: empty
POST requests with other enctype "application/x-www-form-urlencoded" works fine, as it should, hangs only when "multipart/form-data".
Installed on Amazon ec2 virtual server, everything else works fine.
Example > hangs on callback > app.post('/form-file', ... > console.log never trace
app.js:
var http = require('http');
var express = require('express');
var path = require('path');
var app = express();
app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.bodyParser({uploadDir:__dirname + '/public/uploads'}));
app.use(express.methodOverride());
app.use(express.static(path.join(__dirname, 'public')));
});
app.get('/', function(req, res, next) {
console.log('get:/');
res.render('index', { title: 'Upload a single file (using Express BodyParser()) ' })
});
app.post('/form-file', function(req, res, next) {
console.log("multipart/form-data recived... file recived: ",req.files.file.name);
res.send("multipart/form-data recived... file recived: " + req.files.file.name);
});
app.post('/form-text', function(req, res, next) {
console.log("application/x-www-form-urlencoded: txt: ",req.body.txt);
res.send("application/x-www-form-urlencoded... txt: " + req.body.txt);
});
var port = 8001;
http.createServer(app).listen(port, function() {
console.log("Express server listening on port " + port);
});
view:
<code>
form(method="post", name="f", action="/form-file", enctype="multipart/form-data")
fieldset
legend Upload a File
input(type="file", name="file")
div.actions
button.btn.primary(type="submit") Upload
button.btn.cancel(type="button") Cancel
</code>
the same code life on amazon server: http://node.form.co.il:8001/
Update: The problem is in module bodyParser. If it is removed, node will fire response as expected.