Loop binary file


I would like to read binary file and for each row in a file, I would like to call API. How to loop thru each line from the output of read binary.

Sorry if its answered, I couldn’t find the answer.

Hey @dsuresh! :wave:

Do you want to loop through the binary files, or through the content of the files?

If you want to loop through the content of the file, you first have to convert it to JSON. You can use the Move Binary to JSON node for that.

If you want to loop through various binary files you can use the code snippet as shown in the documentation here

Hope this helps! :slightly_smiling_face:

Thanks, want to loop over the contents. Once I use the Move Binary to Json, I can navigate the data set. Thanks.

1 Like

Just to be sure. Did it solve your problem?

Kind of solved, basically need to loop thru file contents (not formatted for json), and call api.

Thinking of function node to parse, but how do i loop? For each iteration need to call api, pls suggest

If you use a Function node and split it into different items the nodes after will loop automatically. That is simply how n8n works. Nodes execute normally once for each item.

So if the HTTP Request node receives 3 items, n8n will make three calls. One for each item.


var recData= new Buffer(items[0].binary.data.data,'base64')

var content = (recData).toString('ascii');

var lines = content.split('\n')

const returnItems = [];

for(j=0;j<lines.length; j++){
  var receiptJSON = "{  \"receipt\" : \" " + lines[j].replace('\n','').replace('\r','') + "\"}"
  var receipt = JSON.parse(receiptJSON)
    returnItems.push({json: receipt});

return returnItems;

I am expecting this to run X number of times, pushing one item at a time to next node. But its only executing once. I don’t have execute once on.

Function nodes always just execute once. Only FunctionItem nodes execute once per item.



Idea is to pass array of values to FUNCTION ITEM, and there by passing that item to HTTP Call. FUNCTION ITEM shows 5 values as expected, but HTTP call is only running once. I thought HTTP call runs 5 times once for each function item.

I also tried FUNCTION, HTTP CALL that didn’t seem to work either.

In both cases, HTTP call only running once. Can you pls explain what do I need to do? I hope you understood what I am trying to achieve.

As always thanks for your patience and willingness to assist.

Yes, the HTTP Request node runs 5 times if it receives 5 items and is not set to “Execute Once”.

Can you please post a few lines of that binary file of yours. You should obviously anonymize the data, just important the the structure is the same. I can then have a look and send you an example.

02-02-2020 John Doe $300.00
09-09-2020 Jake John $200.00

How are the different values separated? Are there tabs between them? Or do you not have to split them apart and they can simply stay as one value?

Space is the delimiter

Actually its working, since only one http call was successful, I thought it ran once. I was able to fix error. working now.


One question related to do this. I have a function returning list of files, and read binary file, which will read one by one. If its one file, I am using items[0].binary.data.data to read file contents in a function. How do I do if Read Binary File in functionItem context, so I can handle multiple files. item.binary.data.data doesn’t work.

You can get the binary data in a FunctionItem-Node by calling getBinaryData().