This article is contributed. See the original author and article here.
Storage Accounts with Data lake Storage gen2 enabled allows us to create directories within container.
When we use When a blob is added or modified (properties only) trigger. It works fine for destination where we are looking for blobs inside containers but not inside any directories.
- It works for these blobs which are directly inside container.
- It won’t work for these blobs which are present inside directory in container.
Even though we choose the location of this directory for When a blob is added or modified (properties only) trigger. The trigger won’t get fired when new blob is created or modified inside directory.
To overcome this, we can use event grid trigger When a resource event occurs.
Make sure Microsoft.EventGrid is registered under resource providers in subscription.
This is webhook type trigger and it registers a webhook with the endpoint. In this case it will be a specified path inside container of a storage account.
- In Event Type we can choose from the given list.
- We need to add a new parameter named prefix filter.
- if we want to register a webhook with any container we can give: /blobServices/default/containers/containerName inside prefix filter.
- If we want to give path of specific directory, we need to append /blobs after container name and then directory names after /blobs.
- for a directory named folder1 inside container container1 the path would be:
Note: the last forward slash ‘/’ after directory name is very important, otherwise you would not get the desired result.
Getting the content of those blobs:
For getting the content inside blobs we can use either HTTP action or get blob content (using path) action.
This is the data object returned after trigger got fired.
We can use either blobUrl or url element from data value to retrieve the path for getting blob content.
- We can use managed identity for HTTP action to get the content from URL.
Expression Inside URI : triggerBody()?[‘data’]?[‘blobUrl’]
You can also use below expression to frame audience from url element of data object.
- Using get blob content :
Expression inside Blob: split(triggerBody()?[‘data’]?[‘blobUrl’],’.net/’)
Brought to you by Dr. Ware, Microsoft Office 365 Silver Partner, Charleston SC.