Can not access getBinaryDataBuffer on n8n cloud

Describe the problem/error/question

I want to access binary data in the code-node, wich gets passed through from outlook. It appears I can not access a helper function on our cloud instance; this.helpers.getBinaryDataBuffer, no matter what I tried so far.

What is the error message (if any)?

Please share your workflow

Share the output returned by the last node

Input to the code node is json with all email data and binary with all attachments.

Information on your n8n setup

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

hello @axp_om

you can use the Extract from File node to get the binary data and use the data from the code node later

2 Likes

Thank you for reporting this. Fixed at #12259. If you can please upgrade to 1.73.0.

2 Likes

We’ve upgraded now, and I was able to properly test it again.

No problem on the self-hosted instance, but an “Unknown Error” on n8n.cloud;

[Node: “Code”]
{ “file”: {
“mimeType”:“application/pdf”,
“fileType”:“pdf”,
“fileExtension”:“pdf”,
“data”:“filesystem-v2”,
“fileName”:“Rechnung_korrektur.pdf”,
“id”:“filesystem-v2:workflows/j06redacted/executions/338/binary_data/1532-redacted”,
“fileSize”:“163 kB”
} }

We are now on n8n version 1.73.1.
Maybe it’s me just getting something wrong here, any help is apreciated.

Looking at the docs the second argument should be a string for the binary property name.

Thanks for pointing that out, apparently I was sloppy when creating the snippet, the 2nd attiribute “data” is indeed set as “data”…

…litteraly copying the code block from your answer also throws an “Unknown error”… but on n8n.cloud only. Doesn’t matter if binary is passed along to the code node or not.

The same workflow on our internal community node outputs different binary data, where a “data” attribute containing base64 encoded data is set, but an “id” is missing. So I just started working with the “data” attribute directly.
(getBinaryDataBuffer here: Cannot read properties of undefined (reading ‘id’))

However that means I could not copy over the workflow from self hosted to cloud and vice-versa, wich gave me a small headache initially.

Anyway it would be nice to figure out a solution for n8n.cloud.
Can you reproduce the error yourself?
We have a mostly fresh instance.

@axp_om The error is definitely something we could improve here. However, you are using the getBinaryDataBuffer wrong. Based on the docs, the first argument is in the item index (e.g. $itemIndex if you are using “Run once for each item”), and second parameter is the property name where the binary file is stored (e.g. data if you are reading the data with ReadBinaryFile node):

const buffer = await this.helpers.getBinaryDataBuffer(0, 'data');

E.g. this is failing on both self-hosted and Cloud:

1 Like

That makes more sense, the helper function accesses the $input binary at index 0.
But on the cloud I don’t get “data” within the binary object, rather a filesystem-id.

=> I converted the binary to a base64 string and was able to work with it afterwards with JSON, to extract am XML file from within the PDF. (ZUGFeRD)

It would be quite helpful to have more options with the code node and an easier debugging experience. But I suppose there’s not much I can do now.

Is there an aproximate ETA when we can expect an updated stable version?

Right. So the reason why the data property in cloud contains a filesystem-id while the self-hosted version contains the base64 encoded data, is that in cloud the N8N_BINARY_DATA_MODE is set to filesystem, while the default mode is default (yes it’s a bit confusing name). The default mode is deprecated and is going to be removed in a future version. I suggest you set N8N_BINARY_DATA_MODE=filesystem so the behaviour is the same in both cloud and self-hosted, and it will work in the future as well.

With this mode the data is not provided directly in the binary property, and you need to use the this.helpers.getBinaryDataBuffer method to get it.

2 Likes