Home > Back-end >  Retrieving more than one blob when using "When a blob is added or modified (properties only) (V
Retrieving more than one blob when using "When a blob is added or modified (properties only) (V

Time:02-14

I've an automated task elsewhere that creates 2 files within an Azure Blob Storage container:

Files stored in Azure Blob Storage

Once this has been done, I then fire a Logic app which has uses the trigger "When a blob is added or modified (properties only) (V2)"

enter image description here

As you can see I have number of blobs to return set to 2, and if we look at the setting I have "split-on" off:

enter image description here

However when logic app is triggered its only retrieving 1 file in the array at a time:

enter image description here

The rest of my logic app is setup to handle and array - as the end game is send an email with a list of attachments, but given how this is being triggered end up with 2 emails each one with a single attachment.

Is this the way this trigger should work? or am I wrong somewhere?

EDIT: Including the code for the trigger: enter image description here

CodePudding user response:

The reason that you are facing this is due to the number of files that you are uploading.

To make this work one of the workarounds is that you can use recurrence trigger having an interval of 1 minute and use a filter array to get the list of blobs that got added for that minute.

enter image description here

In the filter array, I am filtering it for that instance of a minute only. The syntax I'm using here for greater than or equal to operation on the last modified time is formatDateTime(utcNow(), 'yyyy-MM-ddTHH:mm:00Z').

Then I'm using a variable to store the resultant list in an array by having an append to array variable connector for each item.

enter image description here

Then I'm using a Condition Connector to check if I'm receiving anything in the array and then send the list of blobs using the outlook connector. If there is no content or there are no blobs that got added in that minute the goes into false section, else true.

The condition that I'm checking here is the length of the listOfBlobs array:- length(variables('listOfBlobs')) is not equal to 0

enter image description here

So here is what I receive when the length of listOfArray variable is 0, It won't trigger any mail as there are no blobs uploaded and goes into false section.

enter image description here

here is what I receive when the length of listOfArray variable is not 0, It triggers mail with the blob content in it.

enter image description here

Here is what I have uploaded to my storage account:- enter image description here

Here is the mail that triggered in my inbox. enter image description here

[{"pysamp.txt":"{\"Id\":\"<ID>",\"Name\":\"pysamp.txt\",\"DisplayName\":\"pysamp.txt\",\"Path\":\"/container2408/pysamp.txt\",\"LastModified\":\"2022-02-14T05:26:08Z\",\"Size\":58,\"MediaType\":\"text/plain\",\"IsFolder\":false,\"ETag\":\"\\\"0x8D9EF7A8133FFF9\\\"\",\"FileLocator\":\"JTJmY29udGFpbmVyMjQwOCUyZnB5c2FtcC50eHQ=\",\"LastModifiedBy\":null}\\n"},
{"aaa.txt":"{\"Id\":\"<ID>\",\"Name\":\"aaa.txt\",\"DisplayName\":\"aaa.txt\",\"Path\":\"/container2408/aaa.txt\",\"LastModified\":\"2022-02-14T05:26:08Z\",\"Size\":8686,\"MediaType\":\"text/plain\",\"IsFolder\":false,\"ETag\":\"\\\"0x8D9EF7A813F6FFB\\\"\",\"FileLocator\":\"JTJmY29udGFpbmVyMjQwOCUyZmFhYS50eHQ=\",\"LastModifiedBy\":null}\\n"}]

Here is the code view of my logic app

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Compose": {
                "inputs": "@variables('listOfBlobs')",
                "runAfter": {
                    "For_each_2": [
                        "Succeeded"
                    ]
                },
                "type": "Compose"
            },
            "Condition": {
                "actions": {
                    "Send_an_email_(V2)": {
                        "inputs": {
                            "body": {
                                "Body": "<p>@{outputs('Compose')}</p>",
                                "Subject": "Sample",
                                "To": "[email protected]"
                            },
                            "host": {
                                "connection": {
                                    "name": "@parameters('$connections')['office365']['connectionId']"
                                }
                            },
                            "method": "post",
                            "path": "/v2/Mail"
                        },
                        "runAfter": {},
                        "type": "ApiConnection"
                    }
                },
                "expression": {
                    "and": [
                        {
                            "not": {
                                "equals": [
                                    "@length(variables('listOfBlobs'))",
                                    0
                                ]
                            }
                        }
                    ]
                },
                "runAfter": {
                    "Compose": [
                        "Succeeded"
                    ]
                },
                "type": "If"
            },
            "Filter_array": {
                "inputs": {
                    "from": "@body('Lists_blobs_(V2)')?['value']",
                    "where": "@greaterOrEquals(item()?['LastModified'], formatDateTime(utcNow(), 'yyyy-MM-ddTHH:mm:00Z'))"
                },
                "runAfter": {
                    "Lists_blobs_(V2)": [
                        "Succeeded"
                    ]
                },
                "type": "Query"
            },
            "For_each_2": {
                "actions": {
                    "Append_to_array_variable": {
                        "inputs": {
                            "name": "listOfBlobs",
                            "value": {
                                "@items('For_each_2')?['DisplayName']": "@{items('For_each_2')}\\n"
                            }
                        },
                        "runAfter": {},
                        "type": "AppendToArrayVariable"
                    }
                },
                "foreach": "@body('Filter_array')",
                "runAfter": {
                    "Initialize_variable": [
                        "Succeeded"
                    ]
                },
                "type": "Foreach"
            },
            "Initialize_variable": {
                "inputs": {
                    "variables": [
                        {
                            "name": "listOfBlobs",
                            "type": "array"
                        }
                    ]
                },
                "runAfter": {
                    "Filter_array": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            },
            "Lists_blobs_(V2)": {
                "inputs": {
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['azureblob']['connectionId']"
                        }
                    },
                    "method": "get",
                    "path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('AccountNameFromSettings'))}/foldersV2/@{encodeURIComponent(encodeURIComponent('JTJmY29udGFpbmVyMjQwOA=='))}",
                    "queries": {
                        "nextPageMarker": ""
                    }
                },
                "metadata": {
                    "JTJmY29udGFpbmVyMjQwOA==": "/container2408"
                },
                "runAfter": {},
                "type": "ApiConnection"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {
            "$connections": {
                "defaultValue": {},
                "type": "Object"
            }
        },
        "triggers": {
            "Recurrence": {
                "recurrence": {
                    "frequency": "Minute",
                    "interval": 1
                },
                "type": "recurrence"
            }
        }
    },
    "parameters": {
        "$connections": {
            "value": {
                "azureblob": {
                    "connectionId": "/subscriptions/<YOUR_SUBSCRIPTION>/resourceGroups/<YOUR_RESOURCEGROUP>/providers/Microsoft.Web/connections/azureblob",
                    "connectionName": "azureblob",
                    "id": "/subscriptions/<YOUR_SUBSCRIPTION>/providers/Microsoft.Web/locations/northcentralus/managedApis/azureblob"
                },
                "office365": {
                    "connectionId": "/subscriptions/<YOUR_SUBSCRIPTION>/resourceGroups/<YOUR_RESOURCEGROUP>/providers/Microsoft.Web/connections/office365",
                    "connectionName": "office365",
                    "id": "/subscriptions/<YOUR_SUBSCRIPTION>/providers/Microsoft.Web/locations/northcentralus/managedApis/office365"
                }
            }
        }
    }
}
  • Related