gpt4 book ai didi

c# - 使用 http 触发的函数将输入绑定(bind)到表存储

转载 作者:太空宇宙 更新时间:2023-11-03 18:20:43 24 4
gpt4 key购买 nike

是否可以(输入)绑定(bind)到 http 触发函数中的表存储?

我正在尝试使用以下属性将输入绑定(bind)添加到常规 http 触发函数内的表存储:

    [Table("MyTable", "MyPartition", "{httpTrigger}")] MyPoco poco

但是,当我执行它时,它返回以下错误:

[6/5/2019 5:36:38 PM] An unhandled host error has occurred. [6/5/2019 5:36:38 PM] Microsoft.Azure.WebJobs.Host: 'tableStorageInputBindingHttpTriggered' can't be invoked from Azure WebJobs SDK. Is it missing Azure WebJobs SDK attributes?.

此外,在启动时,我收到此异常:

[6/5/2019 6:17:17 PM] tableStorageInputBindingHttpTriggered: Microsoft.Azure.WebJobs.Host: Error indexing method 'tableStorageInputBindingHttpTriggered'. Microsoft.Azure.WebJobs.Host: Unable to resolve binding parameter 'httpTrigger'. Binding expressions must map to either a value provided by the trigger or a property of the value the trigger is bound to, or must be a system binding expression (e.g. sys.randguid, sys.utcnow, etc.).

完整功能如下:

public class MyPoco
{
public string PartitionKey { get; set; }
public string RowKey { get; set; }
public string Directory { get; set; }
}

public static class tableStorageInputBindingHttpTriggered
{
[FunctionName("tableStorageInputBindingHttpTriggered")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
[Table("MyTable", "MyPartition", "{httpTrigger}")] MyPoco poco,
ILogger log)
{


string name = req.Query["name"];

string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
name = name ?? data?.name;

return name != null
? (ActionResult)new OkObjectResult($"PK={poco.PartitionKey}, RK={poco.RowKey}, Text={poco.Directory}")
: new BadRequestObjectResult("");
}
}

我做错了什么?如何在 http 触发的 azure 函数中绑定(bind)到表存储?

最佳答案

问题是 http 触发器返回您一个对象,因此它不知道如何提取您的 key 。

你需要使用路由,它会告诉Function如何获取参数,然后你就可以使用该参数

  public static async Task<HttpResponseMessage> SetLatestAsync(
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "release-set-latest/{program}")]
HttpRequestMessage req,
string program,
[Table(TableName, "latest", "{program}")]FlymarkLatestVersion pocos)

关于c# - 使用 http 触发的函数将输入绑定(bind)到表存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56465532/

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