Accessing blobs from specific directory inside container using event grid trigger
Published Jan 05 2021 12:45 PM 3,028 Views
Microsoft

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.

 

For example:

  • It works for these blobs which are directly inside container.

     pic1.PNG

  • It won’t work for these blobs which are present inside directory in container.

        pic2.PNG

 

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.

 

pic3.PNG

 

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 example:

  • for a directory named folder1 inside container container1 the path would be:

         /blobServices/default/containers/container1/blobs/folder1/

 

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.

 

pic4.PNG

 

"data": {

    "api": "PutBlob",

    "clientRequestId": "clientRequestIdValue",

    "requestId": "requestIdValue",

    "eTag": "eTagValue",

    "contentType": "text/plain",

    "contentLength": 6,

    "blobType": "BlockBlob",

    "blobUrl": "https://storageAccountName.blob.core.windows.net/containerName/folderName/fileNameWithExtension",

    "url": "https://storageAccountName.blob.core.windows.net/containerName/folderName/fileNameWithExtension",

    "sequencer": "sequencerValue",

    "storageDiagnostics": {

      "batchId": "batchIdValue"

    }

  }

 

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.
 

pic5.PNG

 

Expression Inside URI :  triggerBody()?['data']?['blobUrl']

You can also use below expression to frame audience from url element of data object.

concat(split(triggerBody()?['data']?['url'],'net')[0],'net')

 

  • Using get blob content :
 

        pic6.PNG

 

Expression inside Blob: split(triggerBody()?['data']?['blobUrl'],'.net/')[1]

 

Version history
Last update:
‎Jan 05 2021 04:45 AM
Updated by: