简体   繁体   中英

NodeJS serve image from base64

I have a Route on my Meteor App:

    this.route("/userimg/:id", function(){
        console.log("hello");
        img_base64 = Meteor.users.findOne(this.params.id).userimage;
        this.response.writeHead(200, {'Content-Type': 'image/png' });

    },{where: 'server'});

With this Route I want to serve Userimages from my Mongo-Collection. I have a base64 encoded image in my Collection and saving it to varibale img_base64 . My Question is, what do I need to do with my base64 variable to respond it as a png? I need somthing like this.response.end(img_base64,....) . Thanks for your help!

这实际上就是您所需要的(假设img_base64是一个字符串):

this.response.end(img_base64, 'base64');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM