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.
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.
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