dox-foundation-demo node_modules/express/node_modules/connect/lib/middleware/bodyParser.js

multipart

declaration
multipart

    Description

    Module dependencies.

    Source

    var multipart = require('./multipart')
      , urlencoded = require('./urlencoded')
      , json = require('./json');
    • @param: {Object}options
    • @return: {Function}

    Description

    Body parser:

    Parse request bodies, supports application/json,
    application/x-www-form-urlencoded, and multipart/form-data.

    This is equivalent to:

    app.use(connect.json());
    app.use(connect.urlencoded());
    app.use(connect.multipart());
    

    Examples:

     connect()
       .use(connect.bodyParser())
       .use(function(req, res) {
         res.end('viewing user ' + req.body.user.name);
       });
    
     $ curl -d 'user[name]=tj' http://local/
     $ curl -d '{"user":{"name":"tj"}}' -H "Content-Type: application/json" http://local/
    

    View json, urlencoded, and multipart for more info.

    Source

    exports = module.exports = function bodyParser(options){
      var _urlencoded = urlencoded(options)
        , _multipart = multipart(options)
        , _json = json(options);
    
      return function bodyParser(req, res, next) {
        _json(req, res, function(err){
          if (err) return next(err);
          _urlencoded(req, res, function(err){
            if (err) return next(err);
            _multipart(req, res, next);
          });
        });
      }
    };