Home Forums Chapter 7: Forms, Cookies, and Sessions Replacement for bodyParser / connect.multipart()

This topic contains 1 reply, has 2 voices, and was last updated by  Jon J 1 year, 1 month ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #140

    Yaapa
    Keymaster

    If you are using the bodyParser middleware for handling forms, you must be getting this warning message in your Express app.


    connect.multipart() will be removed in connect 3.0
    visit https://github.com/senchalabs/connect/wiki/Connect-3.0 for alternatives
    connect.limit() will be removed in connect 3.0

    Why this warning and how do you resolve it?

    bodyParser is a composite middleware made up of connect.json(), connect.urlencoded(), and connect.multipart(). In Connect 3.0, developers will have to individually include the individual middlewares where required.

    However, there is a problem with connect.multipart(). It will be discontinued because of security concerns. It also is the source for the warning for about connect.limit().

    You will need to find an alternative for connect.multipart(). You might come across formidable, multiparty, and busboy in the process. The stream-based busboy, is the most efficient of them all. However, its interface is a little too complicated for the average Node.js developer; same is the case with connect-busboy, its interface for Connect / Express.

    Introducing Multer, a very user-friendly replacement for connect.multipart(). Best part, it is written on top of busboy.

    So, how do you use Multer?

    Install the package:

    $ npm install multer
    

    Load it in your app:

    var multer = require('multer');
    

    And then, add it in the middleware stack along with the other form parsing middleware.

    app.use(express.json());
    app.use(express.urlencoded());
    app.use(multer({ dest: './uploads/' }));
    

    connect.json() handles application/json
    connect.urlencoded() handles application/x-www-form-urlencoded
    multer() handles multipart/form-data

    For details about Multer and its options, visit the project page on GitHub.

    #154

    Jon J
    Participant

    I created an example that uses Express & Multer – very simple, avoids all Connect warnings

    https://github.com/jonjenkins/express-upload

    Might help someone.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.