【问题标题】:NodeJS serve image from base64NodeJS 从 base64 提供图像
【发布时间】:2016-03-13 12:44:29
【问题描述】:

我的 Meteor 应用上有一条路线:

    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'});

通过这条路线,我想从我的 Mongo-Collection 中提供用户图像。 我的收藏中有一个 base64 编码图像并将其保存到变量 img_base64。 我的问题是,我需要如何处理我的 base64 变量才能将其响应为 png? 我需要像this.response.end(img_base64,....) 这样的东西。 感谢您的帮助!

【问题讨论】:

    标签: javascript node.js mongodb meteor base64


    【解决方案1】:

    这就是你所需要的(假设img_base64 是一个字符串):

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

    【讨论】:

      猜你喜欢
      • 2020-07-17
      • 1970-01-01
      • 1970-01-01
      • 2019-02-20
      • 2017-03-13
      • 2021-06-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多