Set Binary Data with Code node

Describe the problem/error/question

I’m using the Code node and have successfully used this.helpers.getBinaryDataBuffer(0, ‘data’); to read binary data from a previous file read node, then process it into a “buffer” variable.

I can’t find a way to return the “buffer” as a file from the code node.

Using prepareBinaryData gives an “ERROR: body.once is not a function [line 15]” error; is this the right way to do it?

await this.helpers.prepareBinaryData(
   buffer,
  'test',
);

If not, can we confirm how to return “buffer” as a downloadable file? I’ve tried this, it returns stuff in the Output pane, but it seems to be doing it bit by bit… guess I need to read the whole buffer into something first:

return {json: {}, binary:buffer};

Information on your n8n setup

  • n8n version: Latest
  • Database (default: SQLite): Postgres
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system: Linux

Hi @MCPCN, I am so sorry you are having trouble.

The syntax await this.helpers.prepareBinaryData(myBuffer, 'filename.ext'), however, looks correct to me.

I have just tested this using the below workflow on n8n 1.28.0:

This produced the below result:

The file preview confirms this is a valid file:

Perhaps you can share a workflow using which your problem can be reproduced?

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