Looping over binary files uploaded with n8n Form Trigger

Describe the problem/error/question

I am uploading one or more files using the n8n Form Trigger and would like to loop through them for image processing. However, the issue is that only a single item is output from the form, even if multiple files are uploaded. I tried using the Split node, but that causes the binary files to be lost, and my attempt to convert base64 (which I can access anywhere) back to binary was unsuccessful. In the example below, I also tried using the Loop node, but it only processes one file at a time.

How could I achieve that?

Please share your workflow

Information on your n8n setup

  • n8n version: 1.57.0
  • Database (default: SQLite): SQLite
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system:

hello @jburns

you can split files with the Code node

Hey @barn4k! Thanks so much for your help! :slight_smile:

Your suggestion brought me closer to resolving the workflow, but I’ve encountered another issue.

I need two binary files for the Edit Image node with the Composite operation (Original Image + Watermark). To handle this, I updated your script so that it outputs two distinct binary property names based on a condition.

Here’s the updated function:

const data = $input.last().json;
const binaryData = $input.last().binary;

const output = Object.entries(binaryData).map(([key, fileData]) => {
  const fileName = fileData.fileName || '';
  const type = fileName.toLowerCase().includes('watermark') ? 'Watermark' : 'Image';
  
  return {
    json: data,
    binary: { [type]: fileData }
  };
});

return output;

This works as expected, and you can see the result below:

However, when I try to use both Image and Watermark in the next node, it fails because the Watermark binary field can’t be found.


The workflow:

Is it a bug, or is it expected?

Am I right, that you are experiencing issues when you have two+ images and one watermark to apply on all images?

The issue if the same with only one image too. 1 or 2+ images and 1 watermark, same outcome.

image

try this one

added check for watermark field

2 Likes

It’s working! Thank you, @barn4k

Looking at your workflow, I realized that each item only had the Image binary, while the Watermark was in a separate item. The Watermark should have been alongside the other Image items, which is why the Composite node couldn’t find it.

For anyone else interested, I’m sharing the complete workflow I’ll be using. Its purpose is to add a watermark to images and upload them to WordPress.

Thanks again for the support!"

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.