Iterating over e-mail attachments and only go to next step with pdf

Dear community,

I alread looked at Iterating over email Attachments and I’m getting a list of the attachement as a result back.
I would like to reduce the list to only items that are of file type pdf.
if (item.binary.data.fileExtension === “pdf”)
or
if (item.binary.data.mimeType === “application/pdf”)

Don’t do the trick. Any Idea or resource I could read, to create what I want?

Thanks!

Best

  • n8n version: current
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via cloud
  • Operating system: Linux

It looks like your topic is missing some important information. Could you provide the following if applicable.

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

Hi @tuxist,

What I have done is split out the attachments like this

and then use the Filter node (in my case for mp3 files) like this

Hope this helps!

Thanks for your reply, somehome filtering for mimeType or for fileExtension does not work in my end. I tried fileName | mimeType | fileExtension

I worked it out this way:

let results = [];

for (const item of $input.all()) {
  for (key of Object.keys(item.binary)) {
     if (item.binary[key].fileExtension === "pdf") { 
      results.push({
            json: {
                fileName: item.binary[key].fileName,
            },
            binary: {
                data: item.binary[key],
            }
        });
       } 
    }
  
}

return results;

So it only ends up in results, if fileExtension pdf is true

1 Like

Glad you got it to work!

If you are using “is equal to” in the Filter node, you need to leave off the quotes. Alternatively, you can use “contains”.

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