D
D
Denis Sokolov2021-02-13 14:24:21
MongoDB
Denis Sokolov, 2021-02-13 14:24:21

How to get image from mongodb?

// Код который загружает файл в mongoDB
const upload = multer({dest: './uploads/'});

router.post('/setting', upload.single('file'), async (req, res) => {
    const {id} = await req.body

    const {name, surname, birthDay, country, city} = await req.body

    const host = req.host;
    const filePath = req.file.path

    await User.findOneAndUpdate({_id: id}, {
        name,
        surname,
        birthDay,
        country,
        city,
        profilePhoto: filePath
    })

    res.json({filePath, file: req.file})
});

6027b699227db616520859.png
Here is what is in mongoDB when loading a picture there.
6027b6ca9dc5f974943415.png
But when rendering, the picture does not display, but everything is ok with other data.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question