0

Azure Function is not being called for deleted blobs. I am referring sample code - https://learn.microsoft.com/bs-latn-ba/azure/azure-functions/functions-bindings-storage-blob-trigger?tabs=csharp

Below is the sample code -

[FunctionName("BlobTriggerCSharp")] public static void Run([BlobTrigger("samples-workitems/{name}")] Stream myBlob, string name, ILogger log) { log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes"); }

Expected behavior

Azure Functions Blob storage trigger (azure function) should be fired (called) when the blob is deleted from the container

Actual behavior

Azure Functions Blob storage trigger (azure function) is not being fired (called) when the blob is deleted from the container

I am using the latest Package - Microsoft.Azure.WebJobs.Extensions.Storage (version - 4.0.2)

Can someone please help me?

Thanks, Sanjay

1 Answer 1

1

As you see here, that this way you will be able to create a function app that runs when a blob is added to or updated in Blob storage.

You might want to use Event Grid Triggers for this scenario. These events are triggered when a client creates, replaces, or deletes a blob by calling Blob REST APIs.

Sign up to request clarification or add additional context in comments.

7 Comments

Thank you so much for the quick response. Actually my requirement is, whenever the user is uploading new/modifying/deleting files/blobs thru REST API calls, I want to store the entire custom audit trail chain on each file (e.g. user name, last modified time etc.). I am using Blob metadata to do that. But it only saves the current state of the object/blob, not the whole history if the user is taking multiple actions on the same file. I believe by using the Event Grid Trigger will be overkill. Can you please point out the correct way?
It is written "The Blob storage trigger starts a function when a new or updated blob is detected." here - docs.microsoft.com/en-us/azure/azure-functions/…. So, you cannot get deleted events in Blob trigger. Alternative for you is only to use Event Grid so that you get deleted events of blobs as well. In fact, Event Grid Triggers are faster than Blob triggers - youtube.com/watch?v=0sEzimJYhME. Pricing: azure.microsoft.com/en-in/pricing/details/event-grid. It also won't require new code addition in your function app.
Thank you Harshita.. How to get metadata of deleted blob in Event Grid Trigger Azure Function? Can you please also let me know? Below is a sample code -> [FunctionName("EventGridTriggerFunction")] public static void Run([EventGridTrigger]EventGridEvent eventGridEvent, ILogger log) { log.LogInformation(eventGridEvent.Data.ToString()); }}
What do you get in eventGridEvent?
I don't get any blob's metadata in the "data" object/property. Is there any alternate way?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.