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:
- Add a Split Out node.
- Set the Field property to
$binary
. - The node will now output one item for every single binary file present in the input.
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:
- Add an Extract From File node.
- Select Operation: Move File to Base64 String.
- 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.
- Explanation: Since each item now only contains a single binary file, we can ask for the list of binary field names (
- Crucially, ensure you check the option Keep Source - Binary. We need this to retain the file metadata (like
fileName
anddirectory
) for the next step.
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:
- Add a Set node.
- Under Fields to Set, add a new field, let’s call it
path
. - 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 thefileName
. - This expression successfully creates the full path (e.g.,
folder/file.txt
or justfile.txt
).
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:
- Add an Aggregate node.
- Set the Aggregate Property to All item Data (Into a Single List).
- In the Put Output in Field Property, type
files
(This is the top-level array name). - Include property should be All Fields.
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.
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!