Set binary.fileName with incremental number based on the items per array

Hello,

I am trying to set the binary.fileName based on the items per array with a incremental number or possibly via the Binary data number and always start with 01.

For example: when the first array contain 3 images the binary.fileName should become: example_01.jpg, example_02.jpg and example_03.jpg. For the next array that might contain 5 images we start again at _01, _02 etc…

I haven’t found any starting point within the expression examples so my best guess would be to create a function. Do we have any thoughts how to solve this?

Thank you!

n8n setup:

Running via the default docker image
Database: Postgres
Version: 0.164.1

Hey @Maximillion, so for each execution you want to use the incremental filenames for all of your binary data?

Looking at your workflow it seems you have one file per n8n item, that should make things a bit simpler. It also seems you’re already on the right track here with setting the fileName binary property. I’ve made a little tweak to your Function node so it now loops through all items and uses the index of each item as part of the filename:

Example Workflow

This would give you filenames like this at the end:

Is this what you were looking for?

1 Like

Hi @MutedJam, this does exactly what I was looking for and learned allot from the function example and method.

Thank you!

1 Like