使用 Azure 函数的动态输出 blob 路径

MAK*_*MAK 8 javascript azure azure-functions

我有一个由事件中心触发的 Azure 函数。这是我的 index.js 文件的片段。

module.exports = async function (context, eventHubMessages) {
    context.log(`JavaScript eventhub trigger function called for message array ${eventHubMessages}`);

    context.log('Event Hub Trigger: ', JSON.stringify(eventHubMessages));

    const product = context.bindingData.propertiesArray[0].productFilter;

    eventHubMessages.forEach(message =>
    {
      deviceId = message.deviceId;
      context.log('For each message:', JSON.stringify(eventHubMessages));
      context.log('Device ID is', deviceId);
    });
    context.log('Output Device ID is', deviceId);

    if ( product == 'prod1') {


        context.bindings.outputprod1 = eventHubMessages;

    } else if ( product == 'prod2') {

        context.bindings.prod2 = eventHubMessages;
    else {
        context.log("Product not found - " + product);
    }
    return context.done();

};
Run Code Online (Sandbox Code Playgroud)

传入消息中有一个属性 deviceId。我想根据这个值设置输出 blob 路径。

这是我的 function.json 文件。

{
  "bindings": [

    {
      "type": "blob",
      "name": "outputprod1",
      "path": "eventtoblobcontainer/prod1/{datetime:yyyy}/{datetime:MM}/{datetime:dd}/prod1_{rand-guid}",
      "connection": "phiotrawdatadev_STORAGE",
      "direction": "out"
    },
    {
      "type": "blob",
      "name": "outputBlobprod2",
      "path": "eventtoblobcontainer/prod2/{datetime:yyyy}/{datetime:MM}/{datetime:dd}/prod2_{rand-guid}",
      "connection": "phiotrawdatadev_STORAGE",
      "direction": "out"
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

如果我在路径中添加 {deviceId},该函数会给我错误消息,指出命名参数“deviceId”没有值。我尝试在输出绑定中使用函数返回值,但它给了我同样的错误。我怎样才能做到这一点?