How to save multiple email attachments with original filename?

Hello I’m using IMAP Email and Write Binary File nodes to save attachments from email on disk. How can I deal with more than one attachment?

Hey @N8N_userN,

Welcome to the community :sparkling_heart:

Connect the Function node to the IMAP node, and use the following code snippet:

return Object.keys(items[0].binary).map(key => {
  return {
    json: {},
    binary: {
      data: items[0].binary[key],
    }
  }
});

This function will split the binary data, and return each file as an individual item.

Hello! TY for welcome :slight_smile: and answer!
Code works fine, but if I connecting to Function node Telegram node, I receiving double messages for each file.
image

Not problem for me, to connect Telegram to another node. But did it mean, that files writing on disk two times?

Hey @N8N_userN,

Can you share the output from the Function node? How many items does it return?

Two items, as expected.


And workflow (prepairing to use switch with some conditions)

Guess the solution is to connect the Telegram-Node directly to the Switch-Node so it will just run 1x.

Nope.
As I noticed:

Not problem for me, to connect Telegram to another node.

But did it mean, that files writing on disk two times?

If you have two items coming into the ‘write binary file’ node it should execute twice, once for each item (i.e. file). So you shouldn’t be writing individual files two times (unless both items contain the same filename)

Thank you. Just confused Telegram node :slight_smile: