gpt4 book ai didi

c# - Azure Functions Blob 触发器动态绑定(bind)

转载 作者:行者123 更新时间:2023-12-03 04:44:39 24 4
gpt4 key购买 nike

我需要一个 Azure Functions blob 触发器来触发应用设置在运行时提供的存储桶。我读到可以这样做:

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

如果我仅在 appsettings.json 的 Values 字段中包含 BucketName,则此操作在本地有效。

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

如果它不在“值”字段中,则错误如下:

[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.).

我在 Azure 应用程序功能中添加了一个仅包含 BucketName 的设置,但它给了我同样的错误。您能否建议该设置应该被称为什么,或者我在真实的 Azure 环境中实际做错了什么?应该是 Values:BucketName 吗?但我从未在微软网站上看到过以 Values: 作为前缀的示例。

最佳答案

对于您的错误,我测试了一种情况,即未安装 Microsoft.Azure.WebJobs.Extensions.Storage 包。安装后就可以工作了。你可以尝试一下。

关于动态绑定(bind),官方教程上有说明:Binding expressions - app settings 。当您在本地测试时,应用设置值来自 local.settings.json 文件。我不知道你为什么使用appsettings.json。格式就是您粘贴的内容。

在 Azure 上,由于 local.settings.json 中的设置不会通过 VS 部署,您必须转到 Azure Function Configuration,并设置绑定(bind)名称。

enter image description here

enter image description here

我已经测试过,这样它就可以工作,它可以处理我的blob文件。

enter image description here

希望这可以帮助您,如果我误解了您的要求,请告诉我。

关于c# - Azure Functions Blob 触发器动态绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56741669/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com