Binary Data Recovery Pattern using the Code Node - n8n Workflow

Learn how to recover binary data dropped by intermediate nodes in your n8n workflow. This n8n templates uses a powerful custom n8n node code pattern for file persistence.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Advanced n8n users who process binary files (images, PDFs) across multiple steps.
Developers creating complex n8n templates where file integrity is essential.
Users aiming to master the Code n8n node for internal data manipulation.
Anyone needing reliable data persistence within a long-running n8n workflow.

Overview

Many standard n8n nodes, such as the Set n8n node demonstrated here, often do not automatically forward binary data to subsequent steps. This 'data loss' is a common hurdle when building file processing pipelines. This n8n workflow provides a robust technical solution by defining a custom recovery pattern. By utilizing the Code n8n node and the internal $() helper function, the n8n workflow can look back at any specified previous n8n node (even several steps back) and retrieve the original binary payload. This technique ensures data integrity and is a critical pattern for anyone working with sophisticated n8n templates involving complex file transformations.

How it Works

This n8n workflow begins with the Start n8n trigger, initiating the process. First, the 'Get n8n Logo (Binary)' HTTP Request n8n node fetches an image file, creating binary data in the current item context. The subsequent 'Remove Binary Data' Set n8n node then executes. Because the Set n8n node does not preserve binary data by default, the file attachment is lost, simulating a common interruption point in a complex n8n workflow.

The core of this n8n workflow is the 'Re-Access Binary Data from Previous Node' Code n8n node. This custom n8n node executes JavaScript that bypasses the previous node's output and directly accesses the item output of the 'Get n8n Logo (Binary)' n8n node using the $(nodeName).item accessor. The script then iterates through the retrieved binary file's data, uses Buffer.from() to decode it, and utilizes the essential n8n helper function, this.helpers.prepareBinaryData(), to correctly re-attach the recovered binary object to the current item’s execution context, restoring the data path for subsequent n8n nodes in the flow.

Installation Guide


  1. Import: Copy the provided n8n workflow JSON code and paste it into your n8n instance using the 'New' -> 'Import from JSON' option.

  2. Credentials: This specific n8n workflow does not require credentials, as it uses core n8n nodes and a public URL for demonstration.

  3. Customization: If you adapt this n8n template for your own files, ensure you update the previousNodeName variable within the 'Re-Access Binary Data from Previous Node' Code n8n node to match the name of the n8n node that originally generated the binary data you wish to recover.

  4. Execution: Click the 'Run Workflow' button to test the n8n workflow and observe how the binary data is restored after being intentionally dropped by the intermediate Set n8n node.

Node Details

Start (n8n trigger): A manual trigger used to easily initiate this specific n8n workflow for testing and demonstration purposes.
Get n8n Logo (Binary) (HTTP Request): Fetches the n8n logo image from a specified URL, creating the binary data that will be recovered later in the n8n workflow.
Remove Binary Data (Set): This n8n node is configured to add a simple text field ('test value') but intentionally drops the binary data, simulating a scenario where binary files are not automatically passed through intermediate n8n nodes.
Re-Access Binary Data from Previous Node (Code): The central custom n8n node. It contains a JavaScript script that specifically targets the 'Get n8n Logo (Binary)' node's output to retrieve the raw binary object, decodes the Base64 data, and uses this.helpers.prepareBinaryData to re-integrate the file back into the current item stream. The hardcoded variable previousNodeName determines which previous n8n node's output is accessed.

Related n8n Workflows

Free

Nodes: 5 Nodes
Updated: December 26 2025
View all
Created by

Innovative builder with a passion for crafting automation solutions that solve real-world challenges. From streamlining workflows to driving efficiency, my work empowers teams and individuals to achieve more with less effort. Experienced in developing scalable tools and strategies that deliver results with n8n, supabase and cline. Get your Free n8n PDF Audit:

Featured*