Node.js nodejs base64映像响应未作为映像对象出现。添加标题{';内容类型';:';图像/jpeg或png';}
在服务器端生成映像时&获取base64映像字符串 我想将其作为图像对象发送。它通过创建图像流与节点画布正常工作Node.js nodejs base64映像响应未作为映像对象出现。添加标题{';内容类型';:';图像/jpeg或png';},node.js,fabricjs,node-canvas,Node.js,Fabricjs,Node Canvas,在服务器端生成映像时&获取base64映像字符串 我想将其作为图像对象发送。它通过创建图像流与节点画布正常工作 let stream = this.canvas.jpegStream({progressive: true}); this.res.writeHead(200, { 'Content-Type': 'image/jpeg' }); stream.on('data', (chunk) => { this.res.w
let stream = this.canvas.jpegStream({progressive: true});
this.res.writeHead(200, {
'Content-Type': 'image/jpeg'
});
stream.on('data', (chunk) => {
this.res.write(chunk);
});
stream.on('end', () => {
this.res.end();
});
// Working perfectly...!
但当我使用fabric.js时,它返回的是直接的base64图像,而不是base64流式节点画布。
当我发送base64作为响应时,图像变成空白
this.res.writeHead(200, {
'Content-Type': 'image/png'
});
this.res.write(this.fabricCanvas.toDataURL());
this.res.end();
内容类型:image/png
不是用于数据:
URL的正确标题
您可以尝试以下方法之一:
// Preferred: returns a PNG-encoded image buffer
this.fabricCanvas.toBuffer()
// Wasteful - goes from binary to base64 and back
Buffer.from(this.fabricCanvas.toDataURL().split(",")[1], "base64")