Rendering a Base64 PNG with Express

后端 未结 3 1363
小鲜肉
小鲜肉 2020-12-08 11:02

My Node.js server has something that looks like the following:

app.get(\"/api/id/:w\", function(req, res) {
    var data = getIcon(req.params.w);
});
         


        
3条回答
  •  萌比男神i
    2020-12-08 11:21

    Yes you can encode your base64 string and return it to the client as an image:

    server.get("/api/id/:w", function(req, res) {
        var data = getIcon(req.params.w);
        var img = Buffer.from(data, 'base64');
    
       res.writeHead(200, {
         'Content-Type': 'image/png',
         'Content-Length': img.length
       });
       res.end(img); 
    });
    

提交回复
热议问题