This is a follow-up question to this question:
How to delete a blob using Azure Functions?
When a blob triggers my Azure Function, I need to delete it once its processing is done. Otherwise, I will end up with many blobs in the container.
When I run the following code:
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connection);
var blobClient = storageAccount.CreateCloudBlobClient();
var container = blobClient.GetContainerReference("process");
var blockBlob = container.GetBlockBlobReference($"process/in/{name}"); // ==> This was the problem. See the answer for more info.
bool deleted = blockBlob.DeleteIfExists();
the method blockBlob.DeleteIfExists()
always returns false and it never deletes the blob.
My guess is that the blob is somehow locked by the function execution since it just triggered it.
[Update 1]
...
[Update 2]
Many thanks to @Jerry Liu, the issue had nothing to do with Azure Fundctions.
The trick is that blockBlob.DeleteIfExists()
returns false when caller sends a wrong path by mistake.
A better approach could be using 'blockBlob.Delete' and find out what is the actual issue.
See DeleteIfExists source code for more info.
Another related question: Azure CloudBlockBlob.DeleteIfExists() - Does false always mean the blob doesn't exist?