如何在Azure函数中引用声明性绑定中的{rand-guid}值?

问题描述 投票:1回答:1

我有一个C#脚本Azure函数,并将一个blob绑定为function.json中的输出:

"bindings": [
    ...
    {
      "type": "blob",
      "name": "eventOutputBlob",
      "path": "event-receiver-queue-container/{rand-guid}",
      "connection": "DomBlobStorage",
      "direction": "out"
    }
  ],
  "disabled": false
}

我在查找如何在run.csx代码中引用{rand-guid}参数时遇到了麻烦,因此我可以将其存储在队列中以供以后处理。这可能吗?

这不起作用,但是与我希望在run.csx中得到的一致:

public static async Task<HttpResponseMessage> Run(
    HttpRequestMessage req,
    string rand-guid,
    Stream eventOutputBlob, 
    TraceWriter log) {
...
}
c# asp.net azure azure-functions
1个回答
1
投票

事实证明这样做的方法是更改​​方法签名以绑定到CloudBlockBlob而不是Stream

public static async Task Run(
        HttpRequestMessage req,
        string rand-guid,
        Stream eventOutputBlob, CloudBlockBlob queueOutputBlob,
        TraceWriter log) {
    ...
    }

并修改function.json以包含inout每个这Github issue

"bindings": [
    ...
    {
      "type": "blob",
      "name": "eventOutputBlob",
      "path": "event-receiver-queue-container/{rand-guid}",
      "connection": "DomBlobStorage",
      "direction": "out" "direction": "inout"
    }
  ],
  "disabled": false
}

现在我可以调用queueOutputBlob.Name来获取blob的名称,在这种情况下等于{rand-guid}

© www.soinside.com 2019 - 2024. All rights reserved.