# Split binary file data into individual items

**URL:** <https://community.n8n.io/t/split-binary-file-data-into-individual-items/28835>\
**Category:** Questions\
**Tags:** workflow-building\
**Created:** [August 1, 2023, 2:33pm UTC](https://community.n8n.io/t/split-binary-file-data-into-individual-items/28835 "2023-08-01T14:33:26Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gabriele\_Bracciali](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/gabriele_bracciali/32/31293_2.png) [@Gabriele\_Bracciali](https://community.n8n.io/u/Gabriele_Bracciali)\
**Post date:** [August 1, 2023, 2:33pm UTC](https://community.n8n.io/t/split-binary-file-data-into-individual-items/28835/1 "2023-08-01T14:33:26Z")

</div>

## Describe the problem/error/question

Hi I would like to split a **single** binary file into several binary files.  
I’ve found this docs:  
[https://docs.n8n.io/code-examples/javascript-functions/split-binary-file-data/](https://docs.n8n.io/code-examples/javascript-functions/split-binary-file-data/)  
That do the opposite, so from x items to 1 item

Do you have some code example that allow me to do that?

## What is the error message (if any)?

## Please share your workflow

I am downloading a CSV file, binary file, 550MB ish, and I would like to split it in x Binary items

```auto
(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

```

## Share the output returned by the last node

## Information on your n8n setup

- **n8n version:**
- **Database (default: SQLite):**
- **n8n EXECUTIONS\_PROCESS setting (default: own, main):**
- **Running n8n via (Docker, npm, n8n cloud, desktop app):**
- **Operating system:**

---

<div class="post-metadata">

**Author:** ![MutedJam](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/mutedjam/32/70851_2.png) [@MutedJam](https://community.n8n.io/u/MutedJam)\
**Post date:** [August 2, 2023, 10:47am UTC](https://community.n8n.io/t/split-binary-file-data-into-individual-items/28835/3 "2023-08-02T10:47:05Z")

</div>

> I am downloading a CSV file, binary file, 550MB ish, and I would like to split it in x Binary items

Hi @Gabriele_Bracciali, this seems be to be similar to what you were asking for over here:

> [@Convert Binary file To JSON or CSV](http://community.n8n.io/t/convert-binary-file-to-json-or-csv/24593/5):
>
> So this is a bit tricky, but I think a possible approach would be to store that huge file on the file system, then read it in chunks. This will only work if you’re not using n8n cloud though and you would need to adjust the paths used in this workflow to your own folder structure. But the basic idea could be to have a parent workflow like this to download a large file, write it to the file system and then prepare batches: Then call a sub-workflow reading only a limited n…

You can use pretty much the same approach and have your workflow return the smaller binary files produced by the “Move to file” node in the sub workflow back to the parent workflow. This potentially costs a lot memory though, so make sure to monitor this closely.

---

<div class="post-metadata">

**Author:** ![Gabriele\_Bracciali](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/gabriele_bracciali/32/31293_2.png) [@Gabriele\_Bracciali](https://community.n8n.io/u/Gabriele_Bracciali)\
**Post date:** [August 2, 2023, 12:33pm UTC](https://community.n8n.io/t/split-binary-file-data-into-individual-items/28835/4 "2023-08-02T12:33:58Z")

</div>

Hi @MutedJam , yes actually I haven’t thought about that because I was believing that there was a way to do it without downloading the file.

---

<div class="post-metadata">

**Author:** ![MutedJam](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/mutedjam/32/70851_2.png) [@MutedJam](https://community.n8n.io/u/MutedJam)\
**Post date:** [August 3, 2023, 11:07am UTC](https://community.n8n.io/t/split-binary-file-data-into-individual-items/28835/5 "2023-08-03T11:07:49Z")

</div>

> [@Gabriele\_Bracciali](#):
>
> a way to do it without downloading the file.

Hm, I can’t seem think of any way to do this for a file downloaded from an HTTP location, all approaches i can think of would start with fetching that one big file in the first step. You could do it outside of n8n itself through the Execute Command node and a tool like curl or wget, but it would still have to be downloaded.

Or are you perhaps downloading your CSV file from an SSH/SFTP server instead?

---

<div class="post-metadata">

**Author:** ![Gabriele\_Bracciali](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/gabriele_bracciali/32/31293_2.png) [@Gabriele\_Bracciali](https://community.n8n.io/u/Gabriele_Bracciali)\
**Post date:** [August 3, 2023, 11:19am UTC](https://community.n8n.io/t/split-binary-file-data-into-individual-items/28835/6 "2023-08-03T11:19:07Z")

</div>

I am downloading the file from AWS, but so far I am using the solution above and it’s going well, do you have other idea?

---

<div class="post-metadata">

**Author:** ![Gabriele\_Bracciali](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/gabriele_bracciali/32/31293_2.png) [@Gabriele\_Bracciali](https://community.n8n.io/u/Gabriele_Bracciali)\
**Post date:** [August 3, 2023, 1:42pm UTC](https://community.n8n.io/t/split-binary-file-data-into-individual-items/28835/7 "2023-08-03T13:42:09Z")

</div>

hi @MutedJam , following the workflow above, the files that we are going to create will be deleted after the process? or they will stay in memory?

---

<div class="post-metadata">

**Author:** ![MutedJam](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/mutedjam/32/70851_2.png) [@MutedJam](https://community.n8n.io/u/MutedJam)\
**Post date:** [August 3, 2023, 2:02pm UTC](https://community.n8n.io/t/split-binary-file-data-into-individual-items/28835/8 "2023-08-03T14:02:00Z")

</div>

I don’t think AWS S3 files can be manipulated before downloading them, so I don’t think there’s any way around this.

The example workflow does not delete anything. It would, however, write the file into a `/home/node/.n8n/temp/` folder, so to remove the file you could simply run `rm /home/node/.n8n/temp/*` through an Execute Command node at the end of your workflow to clear this temp folder. This will be easy if you use the new version of the Split In Batches node which has a “Done” output.

---

<div class="post-metadata">

**Author:** ![Gabriele\_Bracciali](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/gabriele_bracciali/32/31293_2.png) [@Gabriele\_Bracciali](https://community.n8n.io/u/Gabriele_Bracciali)\
**Post date:** [August 3, 2023, 2:20pm UTC](https://community.n8n.io/t/split-binary-file-data-into-individual-items/28835/9 "2023-08-03T14:20:36Z")

</div>

okay thanks @MutedJam , so I should add the “execute node” with the command, in the write workflow when the split in batches node will finish, right?

---

<div class="post-metadata">

**Author:** ![MutedJam](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/mutedjam/32/70851_2.png) [@MutedJam](https://community.n8n.io/u/MutedJam)\
**Post date:** [August 3, 2023, 2:21pm UTC](https://community.n8n.io/t/split-binary-file-data-into-individual-items/28835/10 "2023-08-03T14:21:54Z")

</div>

Exactly, that would clear up the temp directory 👍

---

<div class="post-metadata">

**Author:** ![Gabriele\_Bracciali](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/gabriele_bracciali/32/31293_2.png) [@Gabriele\_Bracciali](https://community.n8n.io/u/Gabriele_Bracciali)\
**Post date:** [August 3, 2023, 2:24pm UTC](https://community.n8n.io/t/split-binary-file-data-into-individual-items/28835/11 "2023-08-03T14:24:36Z")

</div>

thank you so much for your help, have a good one!

---

<div class="post-metadata">

**Author:** ![MutedJam](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/mutedjam/32/70851_2.png) [@MutedJam](https://community.n8n.io/u/MutedJam)\
**Post date:** [August 3, 2023, 2:25pm UTC](https://community.n8n.io/t/split-binary-file-data-into-individual-items/28835/12 "2023-08-03T14:25:04Z")

</div>

You’re most welcome, have a great afternoon as well!

---

<div class="post-metadata">

**Author:** ![Gabriele\_Bracciali](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/gabriele_bracciali/32/31293_2.png) [@Gabriele\_Bracciali](https://community.n8n.io/u/Gabriele_Bracciali)\
**Post date:** [August 4, 2023, 10:19am UTC](https://community.n8n.io/t/split-binary-file-data-into-individual-items/28835/13 "2023-08-04T10:19:36Z")

</div>

Hi @MutedJam , I’ve received an error in the “Read line” node:  
ERROR: stdout maxBuffer length exceeded

---

<div class="post-metadata">

**Author:** ![MutedJam](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/mutedjam/32/70851_2.png) [@MutedJam](https://community.n8n.io/u/MutedJam)\
**Post date:** [August 7, 2023, 8:27am UTC](https://community.n8n.io/t/split-binary-file-data-into-individual-items/28835/14 "2023-08-07T08:27:44Z")

</div>

Hi @Gabriele_Bracciali, this could suggest you have very long lines in your file (or perhaps even a single very long line?) . You would need to adjust the splitting logic in the parent workflow in this case.

Which result are you seeing on the `Count lines in file` node? Is it more than 1 line? If so, you could try reducing the `linesPerBatch` number on the ` Prepare batches` node in a first step (perhaps try `50` instead of `100` lines per batch).

---

<div class="post-metadata">

**Author:** ![Gabriele\_Bracciali](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/gabriele_bracciali/32/31293_2.png) [@Gabriele\_Bracciali](https://community.n8n.io/u/Gabriele_Bracciali)\
**Post date:** [August 7, 2023, 8:41am UTC](https://community.n8n.io/t/split-binary-file-data-into-individual-items/28835/15 "2023-08-07T08:41:20Z")

</div>

hi @MutedJam I was setted the value you meant at 1000, maybe it’s for that

---

<div class="post-metadata">

**Author:** ![Gabriele\_Bracciali](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/gabriele_bracciali/32/31293_2.png) [@Gabriele\_Bracciali](https://community.n8n.io/u/Gabriele_Bracciali)\
**Post date:** [August 9, 2023, 1:21pm UTC](https://community.n8n.io/t/split-binary-file-data-into-individual-items/28835/16 "2023-08-09T13:21:42Z")

</div>

Hi @MutedJam  
Actually after debug I saw that the problem was in the “Read” workflow:  
I’ve added a node for remove files

This node was the cause of workflow stuck and crashing, once I remove it everything run smooth

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/system/32/195824_2.png) [@system](https://community.n8n.io/u/system)\
**Post date:** [August 16, 2023, 1:22pm UTC](https://community.n8n.io/t/split-binary-file-data-into-individual-items/28835/17 "2023-08-16T13:22:04Z")

</div>

Closed on August 16, 2023, 1:22pm UTC

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