Sign up for your free trial and begin automating your processes today.

The No-Code Evolution: Base64 Encoding Multiple Files in n8n (Part 2)

An updated, code-free guide to converting collections of binary files into Base64 strings using native n8n nodes, replacing the previous custom Code node solution.

In our previous post, From Binary to Base64: A Guide to File Encoding in n8n Workflows, we tackled the challenge of converting a collection of binary files (like those from an unzipped archive) into Base64 strings, complete with their original file paths. We successfully solved the problem, but it required a custom Code node utilizing Node.js’s Buffer class.

While that solution worked perfectly, the best automation is often the one that requires the least maintenance, and that means minimizing custom code whenever possible.

We are happy to share that we’ve found an elegant, purely no-code approach using four standard n8n nodes: Split Out, Extract From File, Set, and Aggregate. This new method simplifies the workflow, improves readability, and keeps everything within the native n8n environment.

Let’s dive into how to replace that custom JavaScript with a robust, node-based solution.

The No-Code Workflow: Four Simple Steps

We’ll assume you already have a collection of binary files in your workflow (e.g., after an HTTP Request and Compression node, as in the previous example).

Step 1: Isolate Files with the Split Out Node

The key reason the standard Extract From File node struggles with multiple files is that they arrive as a single item containing an object with multiple binary fields (e.g., file_0, file_1, file_2).

The Split Out node is the perfect tool to transform this single item with multiple binary fields into multiple individual items, with one binary field each.

Configuration:

  1. Add a Split Out node.
  2. Set the Field property to $binary.
  3. The node will now output one item for every single binary file present in the input.

Screenshot of the Split Out node configuration, showing the ‘Field’ parameter set to the value ‘$binary’ to separate binary items.

Step 2: Dynamic Encoding with Extract From File

Now that we are working with one file per item, we can use the Extract From File node again. However, there’s a small complication: the name of the single binary field is still dynamic (e.g., it might be file_1 for one item and file_5 for another).

This is where a powerful n8n expression comes into play:

Configuration:

  1. Add an Extract From File node.
  2. Select Operation: Move File to Base64 String.
  3. In the Input Binary Field, use the following expression: {{ $binary.keys()[0] }}.
    • Explanation: Since each item now only contains a single binary file, we can ask for the list of binary field names ($binary.keys()) and take the first (and only) one ([0]). This dynamically selects the correct binary file for encoding.
  4. Crucially, ensure you check the option Keep Source - Binary. We need this to retain the file metadata (like fileName and directory) for the next step.

Screenshot of the Extract From File node settings. The ‘Operation’ is set to ‘Move File to Base64 String’, the ‘Input Binary Field’ uses the dynamic expression {{ $binary.keys()[0] }} to target the single binary file, and ‘Keep Source’ - ‘Binary’ is enabled.

Step 3: Extract the File Path with the Set Node

After Step 2, our item contains the Base64 data (as a new field, typically named after the original binary property) and the original binary source metadata. We need to construct the full file path from the metadata.

Configuration:

  1. Add a Set node.
  2. Under Fields to Set, add a new field, let’s call it path.
  3. For the Value of the path field, use the following expression:
{{ $binary[$binary.keys()[0]].directory ? $binary[$binary.keys()[0]].directory + '/' : ''}}{{ $binary[$binary.keys()[0]].fileName }}
  • Explanation:
    • $binary[$binary.keys()[0]] gets the metadata object for the current binary file.
    • $binary[$binary.keys()[0]].directory ? checks if a directory exists. If it does, we append the directory plus a forward slash ('/').
    • If no directory exists (the result is ''), we just append the fileName.
    • This expression successfully creates the full path (e.g., folder/file.txt or just file.txt).

Screenshot of the Set node configuration. A new value field named ‘path’ is being set using a conditional expression to concatenate the binary file’s directory and file name.

Step 4: Aggregate into the Final JSON Array

Our workflow is almost complete! Each item now holds the file’s path and its Base64 data, but they are separate items. The previous Code node solution returned a single item containing a files array—which is often the format required by external APIs.

The Aggregate node is perfect for consolidating this data.

Configuration:

  1. Add an Aggregate node.
  2. Set the Aggregate Property to All item Data (Into a Single List).
  3. In the Put Output in Field Property, type files (This is the top-level array name).
  4. Include property should be All Fields.

Screenshot of the Aggregate node configured with ‘Aggregate’ Property set to ‘All item Data (Into a Single List)’. The ‘Put Output in Field’ Property defines the output array ‘files’.

The Result

After these four simple, native node steps, your workflow achieves the exact same result as the previous Code node—a single item containing a JSON object with a clean files array. Each object in that array holds the path and the Base64 data, ready to be sent to any API that requires this specific, structured format.

Screenshot of the workflow output, showing a single JSON item containing a top-level array named ‘files’. This array holds multiple objects, each successfully containing the reconstructed file ‘path’ and the Base64 encoded ‘data’.

This transition to a pure no-code solution is not just an improvement—it’s a demonstration of how powerful n8n’s native functionality and expression language have become!

A complete n8n workflow diagram showing the no-code chain for Base64 encoding multiple files: HTTP Request, Compression, Split Out, Extract From File, Set, and Aggregate nodes, connected in sequence.

n8n is a trademark of n8n GmbH. This site is not officially associated with n8n GmbH.
Built with Hugo
Theme Stack designed by Jimmy