httpsys icon indicating copy to clipboard operation
httpsys copied to clipboard

using formidable module to parse request body: parse function callback not be called and no error

Open leading00 opened this issue 8 years ago • 0 comments

Hi, I have problem when I use formidable parse function. In my project, I use httpsys to create server (for port sharing), and then I send a post request with multipart form data(including string and zip file). Then I want to use formidable to parse request body. But parse function callback does not be called. There is no error. I do not use Express application, but I use Express Router to route my requests. I already use error handler to catch error, but it never be called (form.on('error', function(err) { console.log(err); });). And I try to use other module like multer or multiparty, but also not work. @tjanczuk Anyone has same problem? Please help me out, thanks in advance.

// main.js var express = require('express'); var router = express.Router(); router.use(function (req, res, next) { for (var i in req.headers) { req.headers[i] = querystring.unescape(req.headers[i]); req.headers[i] = req.headers[i].replace(/+/g, ""); } next(); }); //router.use(bodyParser()); router.post('/TestServer/' + 'TestRequest', function(req, res) { testRequestHandler.execute(req, res); }); var server = require('httpsys').http().createServer(router); var port = '80'; // or other port var listeningPort = 'http://localhost:' + port + '/TestServer/'; server.listen(listeningPort ); // In testRequestHandler var execute = function(req, res) { var form = new Formidable.IncomingForm(); form.uploadDir = uploadDir.getPath(); form.encoding = Constants.ENCODING_UTF8; form.on('file', function(name, file) {console.log('file='+file);}); form.on('error', function(err) { console.log(err); }); // never be called form.on('aborted', function() { console.log('Aborted'); }); form.parse(req, function(err, fields, files) { //todo test code console.log( "parse finished" ); }); }

leading00 avatar May 19 '17 09:05 leading00