@Mike_S I have a different approach to your scenario. To follow along you'll need to switch to the Classic Designer.

Tip: Rename your actions to keep your flow organized!

When a New Email Arrives
Click on Show advanced options. Ensure that you've selected Yes for Include attachments and Only with attachments. This way, your flow will continue to run only if the email has attachments.

If you'd like to speed up your flow building process—I'd recommend replacing the automated trigger with a manual trigger. You can watch this section of a YT tutorial to guide you on how to do this. This way you don't need to send yourself an email each time while you build the flow, rather you can manually trigger the flow on an email already in your inbox.
Filter Attachments Under 40kb
First, you'll need to use a Filter Array action to filter out any attachments under 40kb. Since your requirement is to save attachments that are 12kb, 25kb or 40kb — you should filter out the any attachments over 40kb first.
To learn more about how to use the Filter Array action, please refer to this recent YT Tutorial I uploaded.
Add a Filter Array action after your flow trigger. In the From field, insert the Attachments dynamic content from the flow trigger. Note: I'm using a Get email (V2) action in my flow for demo purposes.
In the first value field, insert the Attachment Size dynamic content. Change the operator to is less than or equal to. In the second value field you can insert the number of bytes you'd like the attachment to be less than or equal to. Attachment sizes are returned in bytes so you will need to convert 40kb in to bytes.

I'm going to use an expression to calculate this. Enter the mul() function into the expression field.

The mul() function takes two numbers and multiplies them. Enter two numbers separated by a comma. In this case 40, 1024.


Return Count of Attachments
Add a Compose action to return the count of filtered attachments. In the expressions tab, insert an expression and use the length() function.

Click on the dynamic content tab and insert the body dynamic content from the Filter Array action above.


Run a test. Verify the number of attachments that have been filtered.

Initialize a String Variable
Add an Initialize Variable action to your flow. give it a name and select String as the type. A variable is like a container and for your scenario—it'll hold the folder name. We'll set the name of the folder based on your conditions (file size).

Condition Check
Add a Condition action to your flow.
In the first value field, insert the output from the compose action above (the one that has the number of items returned from the Filter Array action).
Change the operator to is not equal to and in the second value field insert a zero.

This condition action will check to see whether or not any attachments are equal to or under 40kb. If so, the flow will continue on. All your remaining actions can go into the YES branch. If you want any actions to take place if there are attachments but none of them are 40kb or under in size—you can add those actions to the NO branch.
Apply to Each Attachment
Add an Apply to Each action to your flow and insert the body dynamic content from the Filter Array action.

Get Attachment Dynamic Content
Add a Compose action. I like to use Compose actions to return the dynamic content from a Filter Array action. This can help with troubleshooting. You'll need to get the key for the dynamic content you wan to return.
Refer to this section of a YT Tutorial I uploaded on how to get dynamic content from a Filter Array action.
You can get the dynamic content key from the Filter Array action outputs. The key is the red text between the double quote marks. In this case, you want to return the size of the attachment. The key is 'size'

Insert an expression below.
item()?['']

Between the single quotes, you'll need to insert a key. In this case, it's 'size'
item()?['size']
Add another Compose action to store the Name and Content Byes. Follow the steps above. Important: The keys are case sensitive.

Run a test. Confirm the Compose actions are returning all the dynamic content.


Switch + Set Variable
Add a Switch action to your flow.
A Switch action is a control that allows you to add branching paths based the value entered in the switch. Each branching path you add is referred to as a case. The value entered in a case must match the value in the switch.
In the On field, insert the dynamic content from the Compose action above.

You'll need to create a case for each file size you are looking to match. Remember to rename your cases to keep things organized. You'll need to multiply your kb values by 1024 to get the total bytes.
Add a Set Variable action. Set the variable with the appropriate folder name. In my case I'm calling it 12kb.

Add a new case by clicking the + button. Create a case for each of your requirements. Set the variable in each case.

If there is no match to your cases, you will need to set the variable in the default case. This way your attachments will go somewhere (to another folder if they don't match.

Create File
In the Folder Path, select a folder (if applicable) and add a forward slash right before you insert your variable. Remember that the variable (aka folder name) will be set in the switch action based on the file size of the attachment.

In the File Name field, insert the outputs from the Compose action that has the attachment name.


12kb, 25kb and 40kb are very specific file sizes. My file sizes do not match those requirements which is why my files will be saved in the Temp folder (which is what the variable was set to in the default case).

The Temp folder didn't exist in my OneDrive (which is why it was automatically created).

All my attachments ended up there.

Hope this helps!
If I helped you solve your problem—please mark my post as a solution ✅. Consider giving me a 👍 if you liked my response!
|