node-formidable / formidable

The most used, flexible, fast and streaming parser for multipart form data. Supports uploading to serverless environments, AWS S3, Azure, GCP or the filesystem. Used in production.
MIT License
7k stars 680 forks source link

Attach fields to req.body and files to req.files like multer #952

Closed dawkaka closed 10 months ago

dawkaka commented 10 months ago

Support plan

Community

Context

Allow access to fields and files by attaching them to req body.

What problem are you trying to solve?

So fields and fields are accessible in middlewares

    app.post('/upload-formidable', (req, res, next) => {
        const form = formidable({});
        // this is fine
        form.parse(req, (err, fields, files) => {
            res.json({ fields, files });
        });
       // but should also be able to do this
       req.body    // should be fields object
       req.files // should be files object
    });

Do you have a new or modified API suggestion to solve the problem?

No

GrosSacASac commented 10 months ago

https://github.com/node-formidable/formidable/blob/master/examples/express-middleware.js