将base64图像string转换为可使用node.js提供给浏览器的图像文件

问题在于HTTPvalidation头没有被Restify接受,图像渲染代码是好的。


我有一个图像编码为base64string,我想用这个作为一个图像使用node.js。 目前,我已经得到了下面的代码(我使用Restify),它可以在Chrome浏览器中显示图像,但是图像不会在其他浏览器中显示(尝试IE9,Firefox4,Android浏览器):

var decodedBuffer = new Buffer(dataString,"base64"); res.send({ code: 200, headers: {'Content-Type': 'image/png', 'Content-Length': decodedBuffer.length}, noEnd: true }); res.write(decodedBuffer); res.end(); 

任何人都可以阐明我可能做错了什么?

谢谢

使用数据URI语法 ,这意味着您必须在数据协议和MIMEtypes的前面添加响应,并指定base64编码:

 res.write("data:image/png;base64,"+decodedBuffer);