Azure Functions BlobTrigger Properties Binding Problem

1.1k Views Asked by At

I am trying to create a Azure Function that uses a BlobTrigger to manipulate some files and then save them back into the blob.

To do this I want to be able to access the BlobProperties object to check the Content-Type of the file, to ensure it is supported by my manipulation routine.

It is my understanding from this article that I should simply be able to add a parameter on method called Properties which is of type BlobProperties and I can confirm this works for the other Metadata types listed.

However whenever I add the properties, my app does not work and reports the following error:

The 'Function1' function is in error: Microsoft.Azure.WebJobs.Host: Error indexing method 'Function1'. Microsoft.Azure.WebJobs.Host: Can't bind parameter 'Properties' to type 'Microsoft.WindowsAzure.Storage.Blob.BlobProperties'.

What am I doing wrong? Below is my method:

public static void Run([BlobTrigger("TestContainer/{name}", Connection = "AzureWebJobsStorage")] Stream inputFile,
        string name, string BlobTrigger, IDictionary<string, string> Metadata, ILogger log, BlobProperties Properties)

My target framework is .NET Core 3.1 and the Azure Functions Version is v3. I have the following NuGet packages:

  • Microsoft.Azure.WebJobs.Extensions.Storage 4.0.3
  • Microsoft.NET.Sdk.Functions 3.0.11

I saw a similar post which suggested removing the reference to Extensions.Storage component, but doing so removes the [BlobTrigger] attribute and other types, so does not work. Related questions seem to date back to 2018 and are for older versions of Azure Function, surely this should just work out the box?

Appreciate any suggestions, thank you in advance.

1

There are 1 best solutions below

3
On BEST ANSWER

Just do like below:

using System;
using System.IO;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;
using Microsoft.WindowsAzure.Storage.Blob;

namespace FunctionApp48
{
    public static class Function1
    {
        [FunctionName("Function1")]
        public static void Run([BlobTrigger("test/{name}", Connection = "str")]CloudBlockBlob myBlob, string name, ILogger log)
        {
            string a = myBlob.Properties.ContentType;
            log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Properties.Length} Bytes"+"\n"+a);
        }
    }
}

I can successfully get the content-type of blob:

enter image description here

And the reference package:

<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="3.0.10" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.11" />