Saving image with mongoose

后端 未结 4 1146
情歌与酒
情歌与酒 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-19 11:50

    You know, definitely it's not the best way to save image data on mongo. Instead you can save your image on any directory on your server and save only url of your file, like..

    mongoose-model.js

    avatar : {
        type : String
    }
    

    and on your main script you should get

    let avatar_url = '/path/to/uploads/' + req.body.data.image.file.name
    

    something like this

提交回复
热议问题