Filter for Email Attachments Stops After First PDF – How to Process Multiple PDFs?

What are you trying to achieve?

I’m trying to pass email attachments to ChatGPT (to the vector storage), but only PDF files should be processed. The email may contain multiple attachments (e.g., 2 PDFs and 2 PNGs).

Steps taken so far

I’ve implemented a filter to exclude non-PDF files, but it stops after the first PDF is processed. For example:

If an email has attachments like file1.pdf, file2.pdf, image1.png, and image2.png, the filter removes the PNGs but only processes file1.pdf and ignores file2.pdf.

How can I adjust the filter to handle all PDF attachments in the email, regardless of how many there are?

Current setup:

  1. Trigger: “Watch Emails” (new email arrives).
  2. Iterator: Processes email attachments.
  3. Filter: Intended to exclude non-PDF files (e.g., PNGs).
  4. Action: Upload remaining PDFs to OpenAI.

Filter logic: [Briefly describe your current filter setup]

Thanks for any help!

Screenshots: scenario setup, module configuration, errors




1 Like

Welcome to the Make community!

You probably need to aggregate the files before calling the assistant.

Combining Bundles Using Aggregators

Every result (item/record) from trigger/iterator/list/search/match modules will output a bundle. This can result in multiple bundles, which then trigger multiple operations in future modules (one operation per bundle). To “combine” multiple bundles into a single variable, you’ll need to use an aggregator of some sort.

Aggregators are modules that accumulate multiple bundles into one single bundle. An example of a commonly-used aggregator module is the Array aggregator module. The next popular aggregator is the Text Aggregator which is very flexible and can apply to many use-cases like building of JSON, CSV, HTML.

You can find out more about the other types of aggregator modules here:

Question: Which is the best aggregator do you think you’ll need for your use-case?

Mapping a Specific Structure Into a Complex Field

If you have an array of collections, in programming terms, this is called an array of objects, or an array with non-primitive data types (“complex”).

The Array Aggregator module is very powerful because it allows you to build a new complex array of collections that matches a later module’s field to map multiple items (collections) to it. Such fields initially would allow you to manually add items, but you can toggle the “Map” switch to the “on” state and map a whole array into a single field.

This is done by selecting the “Target structure type” in an Array Aggregator module.

As you can see from the above example, the “Map” toggle on complex fields are used when you have an array variable (like from an array aggregator). Other combinations of modules may also allow you to generate an array that matches a future field’s array structure, like “Aggregate to JSON + Parse JSON”, or “Create JSON + Parse JSON”, but this is an advanced topic.

Question: Are you mapping your array into a field that accepts more than one item/collection?

Example

Here is an example of how your scenario could look like:

This is just an example. Your final solution may or may not look like this depending on your requirements and actual data.

For more information, see “Mapping with arrays” in the Help Centre. You should also do the Make Academy, which also covers the use of Iterators & Aggregators.

Hope this helps! Let me know if there are any further questions or issues.

@samliew

1 Like

Hi @samliew,

First of all, thank you so much for taking the time to explain this in such detail! Your guidance on aggregators and filters was incredibly helpful - I really appreciate how clear and patient you were. :folded_hands:

I tried implementing your suggestions, but I’m still running into a small hiccup. Here’s what I did step by step:

  1. Trigger: “Watch Emails” (new email arrives).
  2. Iterator: Processes all email attachments.
  3. Filter: Set to allow only PDFs
  4. Array Aggregator: Meant to collect the filtered PDFs.

The Issue:


Even though the filter shows it’s blocking PNGs,

the aggregator’s output bundle still contains all 4 original files (2 PDFs + 2 PNGs).

Worse, when I pass this to the next step (e.g., uploading to Nextcloud), it processes one of the PNGs instead of just the PDFs. :sweat_smile:

What I’m Confused About:

  • Why does the aggregator still see the PNGs if the filter removed them?
  • Should I adjust the aggregator’s settings, or is there a mapping step I’m missing?

I’ve attached a screenshots of my setup —maybe I misconnected something?

Thanks again for your kindness and expertise! I’m really grateful for your support and any further tips you might have.

Warm regards


1 Like

Have you tried to set the filter after the aggregator?

The issue might be that the aggregator takes every attachment and doesn’t filter by format.

If you set the filter before the Nextcloud module, it should work.

2 Likes

You are aggregating the incorrect field. Uncheck the “Attachments” field.

Then, try scrolling up and only select fields coming from the Iterator module.

Hope this helps! Let me know if there are any further questions or issues.

@samliew

1 Like

@samliew Thank you for taking the time to look into my issue. :folded_hands:

Still missing a File.

I’ve adjusted the aggregator settings as suggested, selecting the following options:

  • Total number of bundles
  • Bundle order position
  • MIME type
  • File name
  • File size
  • Content-ID
  • Data
  • checksum

The filter processed all 4 files and only allowed the PDFs to pass through.

The aggregator processed 2 bundles, but only one file arrives in the Nextcloud input. However, there should be 2 PDFs uploaded.

I didn’t think it would be so complicated what I have in mind

@Daniel_Muller If I put the filter behind the aggregator, I no longer have the individual files but an array, right? That didn’t work. Or how should it be configured?

1 Like

You likely have mapped the array incorrectly. See “Mapping a Specific Structure Into a Complex Field” above.

Hope this helps! Let me know if there are any further questions or issues.

@samliew

1 Like

As it seems to work basically in your setup, but only the first file is transferred, can you show the input mapping of the Nextcloud module.
Is this look something like this? {{306.array.id}}
image

In this case, only the first document is mapped. The same happens when you leave the space between the two green fields blank.

If you map out of an array, you have to specify which positions you like to map.

2 Likes

@samliew
Thank you for tackling my problem.

I have looked at the help (https://help.make.com/mapping-arrays) but i did not understand how to process all elements, not just the first or another specified one, but all of them.

@Daniel_Muller Thank You
It looks exactly as described by you. I also understood that if the field between the square brackets is empty, only the first element is used. What do I set so that all elements are used and not a specific one?



Is another iterator necessary before uploading to the nextcloud?

Thank you for being so patient and helping me through this!

1 Like

How many pdf do you receive usually? I am not familiar with Nextcloud. I don’t know if you can upload more than one file with one API call.

But you can easily add a second Nextcloud module and map the next data you want to upload. Put a 2 between the green fields for the second file.

If you do it with a second call to Nextcloud add a sleep module (Tools/ Sleep) and set it at 5 seconds. This is used as an error handler to give the API time to reset.

2 Likes

@Daniel_Muller Thank you for continuing to help.

I can’t say exactly, the maximum so far has been 6, but it could be more.
The actual goal is to put these into the vector memory of openai in order to evaluate them. I only added Nextcloud to get the first step done.
The division could be done with a router? right?

1 Like

Yes, a router can separate the files. Add to any route a filter after the router.
Example:

for the second route add the2 between the brackets etc

Maybe you add 8 different routes and if only 3 docs are found those will be processed, the rest of the routes will do nothing as the filter stops them.

3 Likes

@Daniel_Muller Thanks a lot, that worked.

3 Likes