Iterating over email Attachments

Hey @jpm, sorry to hear you’re having trouble here. I assume the problem you’re having is that your binary objects don’t all have the same prefix?

Iirc there was some example code in the docs reading all binary objects and returning them in a single n8n item each with one data binary object, making it rather easier to iterate over them afterwards. Unfortunately it seems this particular snippet got lost with the recent docs revamp :frowning:

From looking at an older fork of the docs I think this snippet used in a Function node would do the job if modified slightly (right now it only looks at the first incoming item).

Here’s an example workflow showing the idea:

Before the Function node there’s 2 items with three different binary objects, each with its own key (file_0, file_1 etc.):

After the Function node there’s 6 items each with a single binary object named data:

Is this what you had in mind?

As for working with binaries in general, this can be a bit tricky and there isn’t much automated logic available for transformations like the one you have described unfortunately. So it’s important to understand how n8n objects look like “behind the scenes” which is described here:

https://docs.n8n.io/data/data-structure/