简体   繁体   中英

Azure Functions Blob Trigger Dynamic Binding

I need an Azure Functions blob trigger to trigger off a bucket that is given at runtime by an app setting. I read it is possible to do this:

[FunctionName("Process")]
public static async Task Process([BlobTrigger("%BucketName%/{name}", Connection = "AzureWebJobsStorage")] Stream avroBlobStream, string name, TraceWriter log)
{
}

This works locally if I have BucketName ONLY in the Values field in appsettings.json.

{
  "IsEncrypted": false,
  "Values": {
    "BucketName": "capture-bucket",
  }
}

If its not in Values field, this is the error:

[6/24/2019 5:52:15 PM] Function 'SomeClass.Process' failed indexing and will be disabled.
[6/24/2019 5:52:15 PM] No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. config.UseServiceBus(), config.UseTimers(), etc.).

I put into Azure App function a setting with just BucketName , but it gave me the same error. Could you suggest what the setting should be called or what I am doing wrong when actually in a real Azure environment? Should it be Values:BucketName ? But I have never seen an example on Microsoft website with Values: as the prefix.

For your error, I have a test one situation is the Microsoft.Azure.WebJobs.Extensions.Storage package is not installed. After installation, it will work. You could have a try.

As for the dynamic bindings, the there is a description on the official tutorial: Binding expressions - app settings . And when you test locally, app setting values come from the local.settings.json file. I don't know why you are using appsettings.json. The format is just what you paste.

And on Azure, cause the settings in local.settings.json won't be deployed with VS, you have to go to you Azure Function Configuration, and set the the binding name.

在此处输入图片说明

在此处输入图片说明

I have test, this way it will work, it could process my blob file.

在此处输入图片说明

Hope this could help you, if I misunderstand you requirements please let me know.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM