Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js nodejs base64映像响应未作为映像对象出现。添加标题{';内容类型';:';图像/jpeg或png';}_Node.js_Fabricjs_Node Canvas - Fatal编程技术网

Node.js nodejs base64映像响应未作为映像对象出现。添加标题{';内容类型';:';图像/jpeg或png';}

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

在服务器端生成映像时&获取base64映像字符串

我想将其作为图像对象发送。它通过创建图像流与节点画布正常工作

    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")