search

Home  >  Q&A  >  body text

node.js - bodyparser已经不和Express绑定在一起了,这个在上传文件时该怎么使用?

bodyparser已经不和Express绑定在一起了,这个在上传文件时该怎么使用?

高洛峰高洛峰2873 days ago599

reply all(1)I'll reply

  • 高洛峰

    高洛峰2017-04-17 15:35:20

    const multer = require('multer');
    const upload = multer({ dest: path.join(__dirname, '../../uploads/') });
    
    _router.post('/resource', upload.single('file'), (req, res) => {
        // req.file
    });
    

    When passed from the front end, the form key is file.

    http://expressjs.com/en/4x/ap...
    https://github.com/expressjs/...

    reply
    0
  • Cancelreply