4

I have the following Azure function triggered when a file is uploaded to Blob Storage

[FunctionName("ImageAnalysis")]
    public static async void Run(
        [BlobTrigger("imageanalysis/{name}", Connection = "AzureWebJobsStorage")] Stream myBlob, 
        string name, 
        TraceWriter log)
    {
        log.Info($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
    }

I want to process the Blob that has been uploaded so ideally I would like it as a CloudBlockBlob instead of a Stream. Then I can just do some work and then delete the blob.

myBlob.DeleteIfExists()

Is there an easy way to cast or convert my Stream to CloudBlockBlob or do I need to use input/output bindings or something else?

Looking through the docs I see examples which use CloudBlockBlob but I can't seem to get it to work so think I am missing something?

1
  • Please expand on "I can't seem to get it to work". CloudBlockBlob is supported. Commented Mar 20, 2018 at 13:34

1 Answer 1

8

Use this syntax for the binding. The trick is specifying FileAccess.ReadWrite in the attribute. The docs rather confusingly refer to this as "inout" for some reason.

[Blob("imageanalysis/{name}", FileAccess.ReadWrite, Connection = "AzureWebJobsStorage")] CloudBlockBlob blob, string name
Sign up to request clarification or add additional context in comments.

5 Comments

I must be doing something wrong I keep getting Microsoft.Azure.WebJobs.Host: Error indexing method 'ImageAnalysis.Run'. Microsoft.Azure.WebJobs.Host: Can't bind Blob to type 'Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob'.
Ignore me I had the wrong version of Microsoft.WindowsAzure.Storage.Blob rolling back to 7.2.1 fixed it
Glad you got it going. Some of the Azure namespaces and assemblies can get very confusing (particularly around the new vs. old queue APIs).
So, the solution is rolling back the library to an old version? I don't think this is a suitable fix.
Since you don't control the deployment platform itself, working with Azure Functions is often more "do what works" than what might seem ideal. (And frankly, due to fiascoes like hard dependencies on old JSON.NET packages and other headaches, we've given up on them for the time being.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.