Express js form data

后端 未结 4 2020
难免孤独
难免孤独 2020-12-02 12:53

Can someone please tell me the recommended (up to date) way to get POSTed form data in express.

So many tutorials/ posts etc talk about bodyParser but this is no lon

4条回答
  •  眼角桃花
    2020-12-02 13:22

    Besides the solutions with formidable, there is another module which I have been using in my recent projects since 2019. The module express-form-data can be easily declared in your server file like:

    const express = require('express');
    const formData = require('express-form-data');
    
    app.use(formData.parse());
    
    app.post('/image-upload', (req, res) => {
      console.log(req.files);
    })
    
    ...
    

    In case of image uploading, for instance, req.files will provide all relevant data you need for handling the files such as path, size, filename, etc.

提交回复
热议问题