azure - 处理 Azure 函数表绑定(bind)中的可选参数

标签 azure azure-functions azure-table-storage

我尝试在 Azure 函数上使用筛选器,根据可选路由参数在表中查找行。如果未提供参数或与行不匹配,则应返回默认行。如果我提供匹配的值或错误的值,这会起作用,我会按照预期得到一行。如果我根本不提供任何值,则会收到以下错误:

执行函数时出现异常:Functions.link。 Microsoft.Azure.WebJobs.Extensions.Storage:未将对象引用设置为对象的实例。

三个关键位(AFAIU)是:

  • httpTrigger 路由:"link/{ref?}"
  • 表格过滤器:“电子邮件 eq '{ref}' 或默认 eq true”
  • 端点 URL:https://[子域名].azurewebsites.net/api/link/(ref)

是否有某种方法可以构造过滤器或路由,以便在未提供可选参数时获得过滤器的第二个子句?或者有更好的方法吗?

我的完整 function.json 如下所示:

{
  "bindings": [
    {
      "authLevel": "anonymous",
      "type": "httpTrigger",
      "route": "link/{ref?}",
      "direction": "in",
      "name": "req",
      "methods": [
        "get"
      ]
    },
    {
      "name": "emailRule",
      "type": "table",
      "take": "1",
      "filter": "Email eq '{ref}' or Default eq true",
      "tableName": "RedirectRules",
      "connection": "TestStorageConnectionAppSetting",
      "direction": "in"
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    }
  ]
}

最佳答案

尝试使用此路由"route": "link/{ref=''}",这样你就没有空值但始终为空字符串

关于azure - 处理 Azure 函数表绑定(bind)中的可选参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67529837/

相关文章:

azure - TableOperation.Insert 始终返回 Conflict 409,TableOperation.InsertOrReplace 成功

azure - 是否可以使用 Azure 表存储进行条件插入

Azure 应用程序见解显示 Node js 应用程序的重复日志条目

c# - 在 HTTPTrigger 函数中找不到 SendGrid

azure - 使用 AKS 时如何修复 "Kibana server is not ready yet"错误

azure - 状态 = 403 代码 ="AuthorizationFailure"消息 ="This request is not authorized to perform this operation"

azure - Set-AzContext 在运行函数的所有实例中设置上下文

Azure 表 "DELETE"返回 "inputs is not valid"

c# - 调试时身份验证成功,但在 Azure 应用服务上身份验证失败

c# - 尝试使用 PowerShell 列出 Azure 文件服务中的共享时身份验证失败