Access binary data from function node using getBinaryDataBuffer()

Describe the issue/error/question

I am trying to access a csv file from a function node because I need to do some programmatic manipulation on it. So I am using the instruction found here Get the binary data buffer - n8n Documentation

In the example below I have pointed the “read binary file” over to the env file, but normally it would point to a csv file. The goal here is to get the binary data into the jsonParser and then manipulate it.

What is the error message (if any)?

TypeError: Cannot read properties of undefined (reading 'id')

Please share the workflow

Share the output returned by the last node

ERROR: Cannot read properties of undefined (reading 'id') [Line 580]
 Details
Stack
TypeError: Cannot read properties of undefined (reading 'id')
    at BinaryDataManager.retrieveBinaryData (/app/code/node_modules/n8n-core/dist/src/BinaryDataManager/index.js:43:24)
    at Object.getBinaryDataBuffer (/app/code/node_modules/n8n-core/dist/src/NodeExecuteFunctions.js:580:64)
    at Object.getBinaryDataBuffer (/app/code/node_modules/n8n-core/dist/src/NodeExecuteFunctions.js:1200:48)
    at BaseHandler.apply (/app/code/node_modules/vm2/lib/bridge.js:479:11)
    at /app/code/node_modules/n8n-nodes-base/dist/nodes/Function:7:47
    at /app/code/node_modules/n8n-nodes-base/dist/nodes/Function:41:2
    at BaseHandler.apply (/app/code/node_modules/vm2/lib/bridge.js:479:11)
    at NodeVM.run (/app/code/node_modules/vm2/lib/nodevm.js:425:23)
    at Object.execute (/app/code/node_modules/n8n-nodes-base/dist/nodes/Function/Function.node.js:96:31)
    at Workflow.runNode (/app/code/node_modules/n8n-workflow/dist/src/Workflow.js:594:51)

Information on your n8n setup

  • **n8n version: 0.182.1

found the issue on line 6 and 7 the variable data is passed into the second parameter of getBinaryDataBuffer() by putting the data in single quotes ‘data’ is becomes happy and starts working.

data = $node.ReadBinaryFile.binary.data
let binaryDataBufferItem = await this.helpers.getBinaryDataBuffer(0, data);

data = $node.ReadBinaryFile.binary.data
let binaryDataBufferItem = await this.helpers.getBinaryDataBuffer(0, ‘data’);

Now I have a new issue getting the binary data into text. From what I can tell I am getting an array of character codes… Pictured below. Any ideas on how to move that into a text string?

Trying to convert the raw data to a normal text string, but getting this error.

data = binaryDataBufferItem.toString(‘utf8’)
return data

ERROR: executionData.every is not a function [Line 772]
 Details
Stack
TypeError: executionData.every is not a function
    at Object.normalizeItems (/app/code/node_modules/n8n-core/dist/src/NodeExecuteFunctions.js:772:23)
    at Object.execute (/app/code/node_modules/n8n-nodes-base/dist/nodes/Function/Function.node.js:97:34)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Workflow.runNode (/app/code/node_modules/n8n-workflow/dist/src/Workflow.js:594:28)
    at async /app/code/node_modules/n8n-core/dist/src

So… looks like here is a functional solution.
Unfortunately I was not able to do it in one function item… and this code could be cleaned up. But the lower route here works, you just have to give it a csv file. This Workflow will take a very large csv file and allow you to break it into many smaller arrays which can be processed a number of ways.

This gets around the 60,000 items limit.

1 Like

Glad to hear you figured it out and thank you so much for sharing your solution!

Sorry it took me a while to respond here (it’s been a busy day :see_no_evil:)

@MutedJam Any ideas on what to do next in order to process that binary data into a text stream?

let binaryDataBufferItem = await this.helpers.getBinaryDataBuffer(0, ‘data’);
// things i tried.
// binaryDataBufferItem.toString(‘utf8’)
// binaryDataBufferItem.toString(‘base64’)