2
votes

Creating Azure Functions targeting .Net Standard 2.0 using Visual Studio 2017.

Using the Add New Azure Function wizard, a blob trigger method is successfully created with the following method signature.

public static void Run([BlobTrigger("attachments-collection/{name}")] Stream myBlob, string name, ILogger log)

This method compiles and works fine.

However, we want to be able access the metadata connected to the CloudBlockBlob being saved to storage, which as far as I know is not possible using a stream. Other answers on this site such as (Azure Function Blob Trigger CloudBlockBlob binding) suggest you can bind to a CloudBlockBlob instead of a Stream and access the metadata that way. But the suggested solution does not compile in latest version of Azure Functions.

Microsoft's online documentation (https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-blob#trigger---usage) also seems to confirm that it is possible to bind the trigger to a CloudBlockBlob rather than a Stream, but gives no example of the syntax.

Could someone please clarify the exact syntax required to enable Azure Function Blob storage trigger to bind to a CloudBlockBlob instead of the standard Stream?

Thanks

2
Did you set FileAccess.ReadWrite in the Blob Attribute as parameter? According to the docs you have to. docs.microsoft.com/en-us/azure/azure-functions/…Sebastian Achatz
In case you get compilation error. Can you please post the message here.Sebastian Achatz
What I'm trying to do is capture the CloudBlockBlob that triggers the function. For this, I believe I need to use the BlobTrigger attribute not the Blob attribute. When I try to set FileAccess.ReadWrite in BlobTrigger attribute, there is a compilation error "'BlobTriggerAttribute does not contain a constructor that takes two arguments".Nick

2 Answers

2
votes

Actually CloudBlockBlob does work, we don't need FileAccess.ReadWrite as it's BlobTrigger instead of Blob input or output.

public static Task Run([BlobTrigger("samples-workitems/{name}")]CloudBlockBlob blob, string name, ILogger log)

Update for Can't bind BlobTrigger to CloudBlockBlob

There's an issue tracking here, Function SDK has some problem integrating with WindowsAzure.Storge >=v9.3.2. So just remove any WindowsAzure.Storage package reference, Function SDK references v9.3.1 internally by default.

3
votes

Thanks to Jerry Liu's s insights, this problem has been solved.

Method: Use the default storage package for Azure Storage that is installed when you create a new Function App

Microsoft.Azure.WebJobs.Extensions.Storage (3.0.1)

This installs dependency

WindowsAzure.Storage (9.3.1)

Then both of the following method signatures will run correctly

public static async Task Run([BlobTrigger("samples-workitems/{name}")]Stream myBlob, string name, ILogger log)

and

public static async Task Run([BlobTrigger("samples-workitems/{name}")]CloudBlockBlob myBlob, string name, ILogger log)