Monday, May 14, 2012

error upload file with node.js

app.js

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



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

res.writeHead(200, {'content-type': 'text/html'});
res.end(
'<form action="/song/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>'
);
});
app.post('/song/upload', function(req, res){

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;
});


Now when I try uploading the file, the browser just keep loading forever.....





No comments:

Post a Comment