GenAI Unplugged

Automate File Management with n8n: Master Binary Data Handling

Handle n8n binary data end to end: automate file uploads, use binaryPropertyName and prepareBinaryData in your workflows.

n8n keeps files as binary data in a binary property on each item, apart from its JSON. Read/Write Files from Disk and HTTP Request move files, Extract From File and Convert To File turn files into JSON and back, and nodes find files by binary property name.

Table of contents

Overview

This lesson is part of the n8n AI Automation - Zero to Hero course, Section: 3. Deep Dive Concepts.

Watch the video above for the full tutorial, or read the written guide below.

How Does n8n Handle Files and Binary Data?

n8n stores files as binary data in a separate binary property on each item, kept apart from the item's JSON. This lets workflows download, read, transform, and upload files like CSVs, PDFs, images, and spreadsheets while still passing structured JSON alongside them.

How to Work With Files in n8n

Use Read/Write Files from Disk to load or save local files, and the HTTP Request node to download or upload them over the web. Convert between formats with Extract From File, which reads a CSV, PDF, or spreadsheet into JSON, and Convert To File, which builds a file from JSON to send onward. Always reference a file by its binary property name so the next node can find it.

How to create a file in the Code node with prepareBinaryData

Sometimes no node builds the file you need, for example a CSV with your own column headers. Well, the Code node can make it with this.helpers.prepareBinaryData(buffer, fileName, mimeType). You pass the content as a Buffer, and n8n returns the binary object that goes under the item's binary key.

const csv = 'name,email\nAsha,[email protected]';
const file = await this.helpers.prepareBinaryData(Buffer.from(csv), 'contacts.csv', 'text/csv');
return [{ json: { fileName: 'contacts.csv' }, binary: { data: file } }];

Use await, because the helper returns a promise. Name the field data, the default binary field name in nodes like Read/Write Files from Disk and the Google Drive upload, so the next node finds the file without extra setup. To read a file already in the workflow, use its partner this.helpers.getBinaryDataBuffer(itemIndex, 'data').

Both helpers are for JavaScript. n8n's docs say getBinaryDataBuffer is not supported in Python, and native Python in the Code node only offers _items and _item. The docs have no page for prepareBinaryData yet, so its signature here comes from the list of helpers n8n exposes to the Code node in its source code.

Sources: Get the binary data buffer, Understand n8n's data structure, Using the Code node and the Code node helper list in n8n's source.

Key Takeaways

  • Binary data in n8n is nothing but a file: a PDF, a PNG or JPG, a video, a ZIP or a CSV. It shows in its own Binary tab, next to the Schema, Table and JSON tabs, where you can view images and download any file.
  • An HTTP Request node with GET and a public file URL downloads the file. It lands in a binary field called data, with the file name, extension, MIME type and size attached.
  • The Gmail node returns attachments only when you turn off Simplify and add the Download Attachments option. One email with 9 attachments is still one item, because the files belong to that email.
  • A Split Out node with $binary as the field to split turns those attachments into separate items, one file each, ready for a loop, a Switch on file type or an upload.
  • The Compression node zips or gzips the files you name in a comma separated list of binary fields. Decompress gives them back as separate binary fields with a prefix, like file_0 and file_1.
  • Nodes run once per input item. A Google Drive upload pointed at file_0 worked for the first item and failed on the next, so either set Execute Once in the node settings or build the field name from each item.
  • Read/Write Files from Disk only works where n8n can reach the disk, so on n8n Cloud use HTTP Request, Gmail, FTP or a cloud storage node instead.

Next Steps

Continue your n8n journey with the full n8n AI Automation - Zero to Hero course.

Frequently asked questions

What will I learn in this lesson?

n8n stores files as binary data in a separate binary property on each item, apart from the JSON. You will learn to read, write, download, and convert files using nodes like Read/Write Files, Extract From File, and Convert To File.

Do I need to watch the previous lessons first?

This lesson builds on earlier concepts. If you are new to n8n, start with Lesson 1 for the best learning experience.

Can I get help if I get stuck?

Join the GenAI Unplugged community on Substack where Dheeraj answers questions and shares additional tips.

Dheeraj Sharma

AI Systems Builder
I teach founders, creators and tech teams to build production-grade AI systems, without an enterprise budget. 20 years of enterprise engineering, now in plain English.

Get the n8n Mastery Bundle

All workflows, cheat sheets, and premium resources from the entire course in one package.

Get Premium Resources