2
votes

I've got an Azure Function defined that uses an Azure Storage Queue Trigger and Blob input bindings. I've got a POCO for the queue trigger but how can I use that POCO with a binding expression in the blob input binding?

Architecuture:

  1. Azure Functions 2.x
  2. Precompiled C# library (.NET Core 2.1)

POCO:

public class ImageToProcess
{
    public int CompanyId { get; set; }
    public string FullImagePath { get; set; }
}

Azure Function:

public static void Run(
    [QueueTrigger("profile-image-queue", Connection = "ProfileImageQueue")]ImageToProcess myQueueItem,
    [Blob("profileimages/{queueTrigger.FullImagePath}", FileAccess.Read, Connection = "ProfileImageBlobConnectionString")] Stream originalImage,
    ILogger log)
{
    log.LogInformation($"Started Processing profile image: myQueueItem");
}

Queue Message:

{ 
    "CompanyId": 123,
    "FullImagePath": "CompanyA/profileImage-original.png" 
}

Error Message:

System.Private.CoreLib: Exception while executing function: ProfileImageUploaded. Microsoft.Azure.WebJobs.Host: Exception binding parameter 'originalImage'. Microsoft.Azure.WebJobs.Host: Error while accessing 'FullImagePath': property doesn't exist.

Resources Used to Create this Solution

  1. http://dontcodetired.com/blog/post/Improving-Azure-Functions-Blob-Trigger-Performance-and-Reliability-Part-2-Processing-Delays-and-Missed-Blobs
  2. https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-queue#trigger
  3. https://docs.microsoft.com/en-us/sandbox/functions-recipes/queue-storage#azure-storage-queue-trigger-using-a-poco

Other Potential Solution: The only other option I see is to use imperative bindings but I'm pretty sure I can use declarative. https://docs.microsoft.com/en-us/azure/azure-functions/functions-dotnet-class-library#binding-at-runtime

1
use the following: "profileimages/{FullImagePath}" or "{FullImagePath}" in the case of the url address - Roman Kiss
@RomanKiss - That fixed it but how does the function know that the property is from the "QueueTrigger" meta data and not some other meta data property? docs.microsoft.com/en-us/azure/azure-functions/… - Mike Becatti
@RomanKiss - After thinking about it I guess the compiler assumes you are trying to reference a property on the queueTrigger meta data because the other meta data properties you must reference by name? Either way, if you add your answer to my post I'll accept it. - Mike Becatti
have a look at the docs.microsoft.com/en-us/azure/azure-functions/…, also it is based on the trigger metadata, e.g. the HttpTrigger will concern a query string, headers. etc., so then {query.myid}, {headers.myid}, etc. - Roman Kiss
@RomanKiss - Yep, this statement under the "JSON payloads" confirms your answer "Notice that the Blob input binding gets the blob name by referring directly to the BlobName property ("path": "strings/{BlobName}")" Thank you! - Mike Becatti

1 Answers

2
votes

use the following in the Blob binding:

"profileimages/{FullImagePath}" 

Note, if the FullImagePath represents a url address, than:

"{FullImagePath}"