2

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://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-queue#trigger
  3. https://learn.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://learn.microsoft.com/en-us/azure/azure-functions/functions-dotnet-class-library#binding-at-runtime

Mike Becatti
  • 2,052
  • 1
  • 16
  • 32
  • 1
    use the following: *"profileimages/{FullImagePath}"* or *"{FullImagePath}"* in the case of the url address – Roman Kiss Oct 04 '19 at 13:57
  • @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? https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-queue#trigger---message-metadata – Mike Becatti Oct 04 '19 at 14:24
  • @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 Oct 04 '19 at 14:46
  • 1
    have a look at the https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-expressions-patterns, 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 Oct 04 '19 at 14:56
  • @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 Oct 04 '19 at 14:59

1 Answers1

2

use the following in the Blob binding:

"profileimages/{FullImagePath}" 

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

"{FullImagePath}" 
Roman Kiss
  • 7,925
  • 1
  • 8
  • 21
  • 1
    Here is the documentation for this: [JSON Payloads](https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-expressions-patterns#json-payloads) – Reyhn Nov 02 '20 at 09:15
  • Without any changes to my application this approach is now suddenly failing. – Mike Becatti Feb 02 '22 at 18:42