Dec 3, 2012

[Solved] JQuery File Upload is Not Working with Express 3

Posted Dec 3, 2012
I tried to incorporate the Node js implementation of JQuery File Upload with Express 3. It uses Formidable middleware for parsing multi-part data which is not compatible with Express 3's body parser. Fortunately, there's a quick fix:

//just replace express.bodyParser() with:
app.use(express.json());
app.use(express.urlencoded());

From Myk's explanation in StackOverflow, Express uses express.bodyParser() as a convenience method to wrap 3 parsers (express.json, express.urlencoded and express.multipart) into one.

Alternative Solution:

Another approach is to redefine the multipart parser of Express (co elmigranto):

var express = require('express');
var bodyParser = express.bodyParser;

bodyParser.parse('multipart/form-data') = function(req, options, next) {
 //custom parser or:
  next();
}

//don't forget to use the variable bodyParser in your configuration




No comments:

Post a Comment