How to bind to iCloudBlob or another (non-string) type

I am trying to create an Azure function that runs when I add an image to a container on my blob memory account.

The only thing that works is when I have a string parameter, but the files are images, so I cannot use a string containing image data.

So, I try every example that I can find on the Internet (not so many), and now I tried the samples from azure webjobs sdk - this is not wokring either. So either I'm stupid, what I feel right now, am I missing something obvious?

There are some errors that I get:

Microsoft.Azure.WebJobs.Host: Error Indexing Method 'Functions.thumbnailgenerator'. Microsoft.Azure.WebJobs.Host: Cannot bind BlobTrigger to type "Microsoft.WindowsAzure.Storage.Blob.ICloudBlob".

Microsoft.Azure.WebJobs.Host: Error Indexing Method 'Functions.thumbnailgenerator'. Microsoft.Azure.WebJobs.Host: BlobTrigger cannot be bound to the type "Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob".

Currently, the function I'm trying to execute is the one shown in the example above, and like many others I tried, it does not work with anything but strings.

So, how do I create a function (with C #) and a function.json file so that it works with blob and preferably a string called blob. Either this, or blob in and one out, where the name outblob is in another container, and the name has a prefix with a hard-coded string.

This is what I got now and it does not work:

function.json

{ "bindings": [ { "type": "blobTrigger", "name": "blob", "direction": "in", "path": "kitimages/{name}.{ext}" }, { "type": "blob", "name": "output", "direction": "inout", "path": "thumbnails/{name}_300_200.{ext}" } ], "disabled": false } 

run.csx

 #r "Microsoft.WindowsAzure.Storage" using System; using Microsoft.Azure.WebJobs.Host; using Microsoft.WindowsAzure.Storage.Blob; public static void Run(CloudBlockBlob blob, CloudBlockBlob output, TraceWriter log) { log.Info($"C# Blob trigger function processed a blob. Blob={blob.Name}"); } 

EDIT . Check out the final solution to my question here: Doing work in the cloud

+5
source share
2 answers

We need to improve the template here, this is a common mistake you encountered (sorry for that!). We fix the GitHub problem: Make it easier for users to run binary blob triggers .

There is a built-in template that communicates with threads. Go to the "New Feature" and select C # for the language and Examples for the script.

For a more advanced selection that uses CloudBlockBlob bindings (which requires an InOut binding direction that has not yet been documented), see the Function sample in the ContosoMoments: DeleteImages Function .

Please note that you can view all the templates in the GitHub repository: https://github.com/Azure/azure-webjobs-sdk-templates .

enter image description here

+4
source

For someone else, I stumbled upon this, although it seems to be the correct setup as above:

I received this message because I had a link to WindowsAzure.Storage in the project.json file. Perhaps because it was an older version (8.1.1) of the library. I dont know. Removing this function made my function work. Since this is a supported DLL, you should simply import it using #r ..

+1
source

Source: https://habr.com/ru/post/1257862/


All Articles