i am new to n8n and struggle to understand some basic concepts like how binary data is handled and how to process in a code node multiple input stream.
In the code below, I am trying to merge the binary data from two different nodes and compress them in order to send them per email (because I failed to send multiple attachments per mail directly).
Some of the questions i have are:
In my code block i have inputs from to nodes, but it seems that that input is not “joined” and accessed at once, but for each input stream separately. How can i change that? The JS code is confusingly appearing to be able to access all elements with $input.all();.
How can in the code node join data through multiple “iterations” if they are executed for each input?
It does not seem to me like data is in some way passed between nodes that are wired together. The wiring only serves to configure an execution graph and to populate some variables like input, or?
Even after reading the docs, binary components are sometimes a challenge, especially if you are dealing with multiple items or multiple (looped) executions of a particular set of nodes. It is something that most people just need to experiment a bit with to understand what you can and can’t do. Here’s an example of using a merge to pass through a binary item along with something derived or extracted in a parallel path.
thank you for your quick response. I am still utterly frustrated with not being able to understand how to perform a simple task like concatenating binaries.
I tried with the following, but as you have written before, combining streams that have a different number of elements does not work.
How can I simple concatenate all binaries from all streams? I tried with code nodes, but had no luck.
You have most of it already. Try adding a Code node, set to Run Once for All Items, following the Merge, that flattens the binaries from all items into a single item with code like this:
In case you notice there are still only 3 items in the resulting zip file, that’s not because the binary items were missing, but because two of them have the same filename (story.txt), and the zip/compress process keeps only one of the two.