Convert multiple images from buffer to string then call them through the rest API

Viewed 24

I have already uploaded images to MongoDB using the code shown below, so I want call all images with other details in API.

    const mongoose = require('mongoose')
    
    const doctorSchema = new mongoose.Schema({
        doctorname: {
            type: String,
            require: true
        },
        clincname: {
            type: String,
            require: true
        },
        doctorresume: {
            type: String,
            require: true
        },
        date: {
            type: Date,
            default: Date.now
        },
        Imagename: {
            type: Buffer,
            require: true
        },
        ImageType: {
            type: String,
            required: true
        },
        
    })

module.exports = mongoose.model('Doctors', doctorSchema)

this is code of route to retrieve all data through API:

router.get('/alldoctors', async (req, res) => {
    const results = await Doctors.find()
    res.json(results)
    
})
0 Answers
Related