Binary Data MIME Type and File Extension Conversion Utility - n8n Workflow

Use this core logic n8n workflow to reliably change the file extension and associated MIME type of binary data passing through your n8n automation. Essential for consistent file processing.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Automation Developers: Those building complex n8n workflows that handle file manipulation.
Integration Specialists: Users who need to ensure file integrity and correct MIME type headers when transferring files between different services (e.g., S3 to an API).
n8n Users: Anyone dealing with binary data where the source service provides an incorrect file extension or MIME classification.
Users looking for robust, reusable n8n templates for data transformation.

Overview

Mismatched file extensions or incorrect MIME types can often break integrations, especially when dealing with APIs that require strict file validation. This powerful utility n8n workflow solves this by providing a standardized method to take any incoming binary file and reconstruct it with a user-defined file extension and corresponding MIME type (e.g., ensuring a file is correctly treated as image/png instead of application/octet-stream). It acts as a reliable helper within larger n8n workflows, ensuring smooth and predictable file handling across your entire n8n automation pipeline.

How it Works

This reusable n8n workflow is designed to be triggered either manually or as a sub-workflow call via the initial n8n trigger (Execute Workflow Trigger) which accepts binary data input.


  1. Configuration and Key Capture: The process starts at the SET OUTPUT FILE NAME n8n node. This node dynamically captures the name of the incoming binary property (binarykey) and allows the user to define the desired file name and extension (outputfile_name). This extension is the crucial piece of information used to determine the new MIME type.

  2. Data Preparation: The Extract from File n8n node converts the raw binary data into a Base64 text string. This is necessary because it allows the subsequent code step to easily manipulate the data within the standard JSON structure.

  3. Binary Rebuilding and Type Change: The core logic resides in the Change Binary Data Type n8n node (a Code node). It reads the Base64 data, converts it back into a binary buffer, and then uses the n8n helper function this.helpers.prepareBinaryData. By providing the newly configured file name and extension during this preparation, the n8n node forces the binary object metadata to reflect the desired file type, completing the conversion.

Installation Guide

To utilize this functionality within your automation projects, follow these steps:


  1. Import the n8n workflow: Copy the provided JSON data and paste it directly into your n8n canvas using the 'New' -> 'Import from JSON' function.

  2. Review the n8n trigger: The workflow starts with an 'Execute Workflow Trigger'. If you intend to run this as a standalone utility, you can replace this with a manual test trigger or HTTP Request n8n node.

  3. Configuration Focus: Navigate to the SET OUTPUT FILE NAME n8n node.

  4. Set Output File Name: Change the value for the outputfilename assignment. This value must include the desired file extension (e.g., image.png, document.pdf, song.mp3). The extension dictates the new MIME type recognized by subsequent n8n nodes.

  5. Review binarykey: The binarykey assignment uses an expression (={{ Object.keys($binary).first() }}) to automatically detect the incoming binary file name. Do not change this value.

Once configured, this reusable logic can be integrated into your main n8n templates.

Node Details

Change Binary MimeType/Extension (Execute Workflow Trigger n8n trigger):
Function: Serves as the starting point, typically used when calling this as a sub-workflow from another primary n8n workflow.
Key Configuration: Input Source set to 'Passthrough' to ensure incoming binary data is preserved.
SET OUTPUT FILE NAME (Set n8n node):
Function: Captures the unique binary property key and stores the user-defined output file name/extension.
Key Configuration: Defines outputfilename (e.g., audio.mp3) which controls the resulting MIME type, and dynamically sets binary_key using a variable expression.
Extract from File (n8n node):
Function: Converts the binary file stream into a Base64 encoded string property named data for easy manipulation in the next step.
Key Configuration: Operation set to 'Binary To Property'.
Change Binary Data Type (Code n8n node):
* Function: Executes the core logic. It reads the Base64 string, converts it back to a Buffer, and uses the n8n helper prepareBinaryData along with the configured file extension to recreate the binary object with the correct new MIME metadata. This is the heart of this n8n workflow logic.

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.

Featured*