Best way to show images in a custom node

Describe the problem/error/question

I’ve been working on showing an image in a custom declarative node.

I found the fileType field in the binary data returned, and no clear documentation on how to do complex declarative nodes, such as how to show a binary data for instance.

Is there a more complete “how to build your own node” documentation that docs.n8n.io? Is this routing.output.postReceive the best way to show an image, or is there another way that would be totally different? (I have multiple HTTP requests in my node and only one that returns an image, so I don’t want to do a run function just for one endpoint.)

{
    postReceive: [async (items): Promise<INodeExecutionData[]> => {
        let bufferData = Buffer.from(items[0].json as unknown as ArrayBuffer);
        const base64Data = bufferData.toString('base64');
        return [{
            binary: {
                data: {
                    data: base64Data,
                    mimeType: 'image/png',
                    fileSize: bufferData.length.toString(),
                    fileType: 'image'
                },
            },
            json: {},
        }];
    }],
}

What is the error message (if any)?

Please share your workflow

(the most basic one, I don’t think it matters)

Share the output returned by the last node

The output is what I want, my question is more about implementation.

Information on your n8n setup

  • n8n version: 1.80
  • Database (default: SQLite): default I think
  • n8n EXECUTIONS_PROCESS setting (default: own, main): default I think
  • Running n8n via (Docker, npm, n8n cloud, desktop app): docker
  • Operating system: ubuntu 24.04

I had the same issue as you before and it seems you can’t do that with declarative nodes. So I ended up converting it into programmatic node in order to receive my image correctly.

To get an idea you check have a look at my code on github:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.