Use Multer in Express Route? (Using MEANJS)

前端 未结 3 1346
既然无缘
既然无缘 2020-12-29 09:00

I\'m using Multer to upload images in Express 4. However, the examples all show Multer being defined in the express file as Middleware. I\'d like to actually define some of

3条回答
  •  梦谈多话
    2020-12-29 09:25

    Actually you can do what you want with another method:

    var express = require('express');
    var multer  = require('multer');
    var upload = multer({ dest: './uploads/'});
    var app = express();
    
    app.get('/', function(req, res){
      res.send('hello world');
    });
    
    // accept one file where the name of the form field is named photho
    app.post('/', upload.single('photho'), function(req, res){
        console.log(req.body); // form fields
        console.log(req.file); // form files
        res.status(204).end();
    });
    
    app.listen(3000);

提交回复
热议问题