1
votes

Please help in resolving this issue.

I have two Azure blob storage accounts storage1 and storage2, how to write an azure function that should trigger once any files are uploaded to the storage accounts.

1
have you tried this tutorial?: docs.microsoft.com/en-us/azure/azure-functions/…hujtomi
yes Tamas, i went through this blog, but i have to write multiple azure functions to trigger multiple storage accounts. I can able to achieve this scenario by creating azure event grid triggers, which triggers multiple storage accounts using single azure function.Tanjila

1 Answers

-2
votes

You can just create 2 functions which are triggered on these 2 different blobs, and create one method where you process the files, something like this:

Function1:

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

Function2:

public static class Function2
{
    [FunctionName("Function2")]
    public static void Run([BlobTrigger("samples-workitems/{name}", Connection = "AzureWebJobsStorage2")]Stream myBlob, string name, ILogger log)
    {
        new MySharedCode().Process(myBlob, name, log);
    }
}

And have some shared code where you process the uploaded files:

class MySharedCode
{
    internal void Process(Stream myBlob, string name, ILogger log)
    {
        // Process the file
    }
}

In the settings file you have to set up your storage connection strings:

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "{connection string to storage1}",
    "AzureWebJobsStorage2": "{connection string to storage2}",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet"
  }
}

It works fine for me. The idea is based on this github thread: https://github.com/Azure/azure-functions-host/issues/1544