Saving image with mongoose

后端 未结 4 1154
情歌与酒
情歌与酒 2021-02-19 11:22

I know there are quite a few threads on this topic already, but unfortunately I didn\'t find my answer until now. I use angular.js with the example code from http://angular-js.i

4条回答
  •  故里飘歌
    2021-02-19 11:28

    If you are using express than you can use express-fileupload middleware to upload files.

    const fileUpload = require('express-fileupload');
    app.post('/upload', fileUpload, (req, res) => {
      //Now you can use req.files.file to access the file input with name="file"
      user.avatar = {data: req.files.file.data, contentType: req.files.file.mimetype};
      //Now perform user.save
    })
    

提交回复
热议问题