2
votes

I have a Azure Storage account with several containers. I am using BlobTrigger Function to detect new blobs.

Now this is seems working perfectly. But a BlobTrigger only works on one container. Seems like a bad idea to create one trigger pr container (I will duplicate a lot of code).

Is there any way to simplify this? Ideas are appreciated.

PS: I know that BlobTrigger is not reliable if there are 10K blobs or more in the container (but this is not my case).

1

1 Answers

1
votes

Is there any way to simplify this? Ideas are appreciated.

An Azure Storage blob trigger only lets you monitor one storage container for new and updated blobs. If you want to monitor multi containers in a Azure Storage Account, you need to create multi functions.

I suggest you write the blob changed processing logic in one method and invoke this method when other functions are called.

public static void ProcessBlob(string containerName, string blobName, CloudBlockBlob blob)
{
    //Write your logic here
}

public static void ProcessBlobContainer1([BlobTrigger("container1/{blobName}")] CloudBlockBlob blob, string blobName)
{
    ProcessBlob("container1", blobName, blob);
}

public static void ProcessBlobContainer2([BlobTrigger("container2/{blobName}")] CloudBlockBlob blob, string blobName)
{
    ProcessBlob("container2", blobName, blob);
}

There is open issue on GitHub which related to your question, hoping that it will be solved soon.

Add ability to create blob triggers on a container names that match a pattern