【问题标题】:Azure Functions with blob storage. How to create a BlobTrigger to a sub-folder?具有 Blob 存储的 Azure Functions。如何为子文件夹创建 BlobTrigger?
【发布时间】:2018-06-26 20:38:45
【问题描述】:

我需要对添加到子文件夹中的 blob 做出反应。我知道 blob 存储无法识别文件夹,它们只是虚拟的,但如果文件被添加到子文件夹,我仍然不知道如何创建 blob 触发器。

例子:

摘自function.json { "name": "myblob", "type": "blobTrigger", "direction": "in", "path": "rootContainer/{name}" }

好的,触发了一个函数,我收到了 blob

摘自function.json { "name": "subfolder/myblob", "type": "blobTrigger", "direction": "in", "path": "rootContainer/{name}" } 或者 { "name": "myblob", "type": "blobTrigger", "direction": "in", "path": "rootContainer/subfolder/{name}" }

不行,没有触发函数

关于这个问题的问题不多,他们仍然没有提供正常的答案。在文档中也找不到任何信息。

谢谢!

【问题讨论】:

  • 第二个配置应该可以工作。确保您上传到正确的文件夹并且您的子文件夹名称正确。
  • 根据我的测试,如果我们使用"path": "rootContainer/subfolder/{name}",它可以正常工作,这是我的result screenshot,我发现你的function.json 中没有connection,可能是这个原因造成的吗?但是你说它可以和rootContainer/{name}一起使用,很奇怪,我建议你换一个存储帐户或资源管理器再试一次。
  • 是的,为了简洁,我省略了connection。我注意到它在根为rootContainer 时被触发,并且附带的blob 具有以下名称subfolder/{name}。它不会因为路径为 rootContainer/subfolder 而被触发。
  • @Semuserable 您是在本地还是在门户(您的运行时版本 v1 或 v2)上运行此触发器?
  • 我尝试在门户上运行它,运行时版本是~1

标签: azure azure-storage azure-blob-storage azure-functions


【解决方案1】:

简而言之,"path": "rootcontainer/subfolder/{name}" 应该可以工作。

功能门户上的日志面板可能无法及时显示日志,您可以转到https://{functionappname}.scm.azurewebsites.net/DebugConsole,然后导航到D:\home\LogFiles\Application\Functions\function\yourblobtriggername查看日志文件。

如果您在函数代码中使用 blob 名称,path 应包含 {name},否则函数将因运行时异常而无法运行。

如果您将path 设置为mycontainermycontainer/{name} 等容器,则写入该容器的所有文件(包括上传到虚拟子文件夹的文件)都会触发该功能。 正如你所提到的:

当 root 为 rootcontainer 时触发,并且 blob 具有以下名称 subfolder/{name}

如果将其设置为mycontainer/subfolder/{name}这样的子文件夹,则只有写入该子文件夹的文件才会触发该功能。

如果设置为mycontainer/subfolder,则不会像您发现的那样触发。

如果您还有其他问题,请随时提问。

【讨论】:

  • 是的,你是对的。它正在工作,但运行起来非常奇怪。有时它是瞬时的,有时它需要长达 5 分钟。不幸的是,可以找到任何相关性。
  • @Semuserable 你可能见过cold start in consumption plan,还有some reliable research供你参考。
  • 感谢您的链接!我一定会深入研究这种行为。
猜你喜欢
  • 2014-12-30
  • 2019-10-23
  • 2019-05-18
  • 1970-01-01
  • 2015-07-11
  • 1970-01-01
  • 1970-01-01
  • 2020-11-07
  • 1970-01-01
相关资源
最近更新 更多