如何使用<img>标签在html中显示来自猫鼬的图片?

时间:2019-09-09 23:15:21

标签: node.js

我有以下代码,它们从猫鼬数据库中获取图像     然后,我想使用标签在车把模板中显示图像。

app.get('/p',(req,res)=>{
    //the image id in the mongoose
    let id=Object("5d76d6af1c7cce2ee0f5b111");
    //find the image given the id above
    dbCollection.findOne({_id:Object(id)},(err,result)=>{
        if(err){
            console.log("Can not display the image" +err);
        }
        //gets the buffer of the image
        let buff = result.img.buffer;
        //converts the buffer into base64
        let imgSrc = `data:${result.mimiType};base64,`+ buff.toString('base64');
        res.render('databasefiles',{imgSrc:imgSrc });
    })
});

this is my "databasefiles" handlebars I omitted the tags in here:
div class="myForm"
        img src="{{imgSrc}}" alt=""
/div


    enter code here

Nothing shows up when I open the handbars template,
Can someone please help me?

0 个答案:

没有答案