Based on a tutorial by NN Tutorial Creator
Are you struggling to efficiently handle files in your NN workflows? You’re not alone. Managing files, especially when dealing with images, documents, or compressed archives can be one of the more challenging aspects of workflow automation.
I’ve summarized this excellent tutorial to help you quickly master file handling in NN without having to watch the entire video. This is video #7 in the Advanced NN Course series, focusing specifically on working with binary data in your workflows.
Quick Navigation
Introduction to Binary View in NN (00:00-01:15)
When working with files in NN workflows, the node output displays a new option called “Binary View” alongside the familiar JSON, Table, and Schema views. This feature is essential when handling images, documents, or any other file types.
Key Points:
- Binary View shows additional information about files (name, directory, type, size)
- When dealing only with files, the Table, JSON, and Schema views remain empty
- You can preview compatible files directly in the interface
- Files can be downloaded to your local machine directly from the Binary View
My Take:
The Binary View is a game-changer for workflows that process visual assets or documents. Being able to preview files directly within the interface saves significant time compared to downloading and opening them externally each time.
Key File Nodes Overview (01:16-02:10)
NN provides several specialized nodes for file operations, all conveniently grouped in the “File” category of the node library. These nodes enable comprehensive file management within your workflows.
Key Points:
- Compress/Decompress nodes for handling ZIP archives
- Read/Write File nodes for disk operations (especially useful for self-hosting)
- Conversion nodes for transforming between JSON objects and file formats
My Take:
The file handling capabilities in NN are quite robust compared to some other automation platforms. If you’re self-hosting NN, the disk operation nodes become particularly valuable for creating workflows that interact with your local file system.
Handling Files from HTTP Requests (02:11-03:40)
The tutorial demonstrates how to fetch files using HTTP requests and how binary data is handled differently than regular JSON responses in NN workflows.
Key Points:
- HTTP Request nodes can retrieve files when “File” is selected as the expected response format
- Retrieved files are stored in specified fields (e.g., “logo” in the example)
- Binary items append to each other rather than overwriting in sequential nodes
- Multiple binary files can be collected in a single workflow execution
// Example of HTTP Request node configuration for file retrieval
{
"url": "https://domain.com/nn-logo.svg",
"method": "GET",
"responseFormat": "file",
"responsePropertyName": "logo"
}
My Take:
The ability to append binary items is incredibly useful for building workflows that gather multiple files from different sources before processing them together. Just remember that you need to keep track of your field naming when working with multiple files.
Compressing Multiple Files (03:41-04:25)
After collecting multiple files in your workflow, you might need to compress them for storage or transfer. The tutorial shows how to use the Compress Files node to bundle multiple binary items into a single ZIP archive.
Key Points:
- The Compress Files node handles both compression and decompression
- You must specify which binary fields to include in the archive
- Set the output format to ZIP and provide a filename for the archive
- The resulting compressed file can be downloaded directly from the node output
My Take:
This compression feature is particularly valuable when building workflows that need to deliver multiple files to users or other systems as a single package. For example, bundling generated reports with supporting images or data files.
Decompressing Archives (04:26-05:40)
The reverse operation is equally important – extracting files from compressed archives. The tutorial demonstrates how to retrieve a ZIP file and extract its contents for further processing.
Key Points:
- Use HTTP Request to fetch a ZIP file from a server
- The Decompress node extracts all files contained in the archive
- Extracted files appear as a single item with multiple binary files
- Each extracted file includes metadata (name, type, size)
My Take:
This decompression capability opens up interesting workflow possibilities – you could create systems that process uploaded ZIP archives from users, extracting and processing multiple files in a single operation. Just be mindful that at this stage, all files are still part of a single workflow item.
Splitting Binary Items with Code Node (05:41-06:30)
To process extracted files individually, you need to split the single item containing multiple binary files into separate items. The tutorial shows how to accomplish this using a Code node.
Key Points:
- After decompression, all extracted files exist within a single workflow item
- Use a Code node to split binary files into separate items
- Template code is available for this common operation
- After splitting, each file becomes an individual binary item that can be processed independently
// Example code structure for splitting binary files
// (Check NN templates for the exact implementation)
return items.flatMap(item => {
const results = [];
for (const binaryKey of Object.keys(item.binary)) {
for (const fileKey of Object.keys(item.binary[binaryKey])) {
const newItem = {
json: {},
binary: {}
};
newItem.binary[binaryKey] = item.binary[binaryKey][fileKey];
results.push(newItem);
}
}
return results;
});
My Take:
This splitting technique is critical for workflows that need to process each file differently. For example, if you’re extracting images from a ZIP archive and need to resize each one separately or run them through different analysis tools, you’ll need this pattern.
This article summarizes the excellent tutorial created by NN Tutorial Creator. If you found this summary helpful, please support the creator by watching the full video and subscribing to their channel. This is video #7 in their Advanced NN Course, and video #8 will cover Enterprise features to take your workflow building to the next level.