我已关注Microsoft tutorial处理基于 Azure 存储中创建的 blob 的事件。
事件正在触发,但由于 EventGrid 事件未填充输入流参数,因此处理图像的事件代码被绕过。这应该通过 blob(图像文件)的路径来处理。
public static async Task Run(
[EventGridTrigger]EventGridEvent eventGridEvent,
[Blob("{data.url}", FileAccess.Read)] Stream input,
ILogger log)
{
try
{
log.LogInformation("Entered Thumbnail Function ..");
if (input != null)
{ //doesn't get to here ..
每次事件触发时的日志是
2018-11-15T05:33:41.096 [Information] Executing 'Thumbnail' (Reason='EventGrid trigger fired at 2018-11-15T05:33:41.0781270+00:00' ..
2018-11-15T05:33:41.096 [Information] Entered Thumbnail Function
2018-11-15T05:33:41.096 [Information] Executed 'Thumbnail' (Succeeded,
2018-11-15T05:33:41.096 [Information] Executing 'Thumbnail' (Reason='EventGrid trigger fired at 2018-11-15T05:33:41.0781270+00:00',
2018-11-15T05:33:41.096 [Information] Entered Thumbnail Function
2018-11-15T05:33:41.096 [Information] Executed 'Thumbnail' (Succeeded,
最佳答案
本教程适用于 v1 c# script function正如你所看到的,它提到了 csx file当谈论功能代码时。但现在项目链接指向v2预编译代码,如果我们严格按照教程进行更改代码,可能会出现问题。
让我们通过两个步骤来解决不一致问题。
关键点是函数未连接到 part1 中创建的 blob 存储帐户,因此我们得到了空输入流。
由于我们在 this step 中创建了应用设置
myblobstorage_STORAGE
,我们只需将它添加到我们的函数代码中即可。public static async Task Run( [EventGridTrigger]EventGridEvent eventGridEvent, [Blob("{data.url}", FileAccess.Read, Connection = "myblobstorage_STORAGE")] Stream input, ILogger log)
在同一步骤中,教程为 part1 中 Blob 存储帐户中创建的容器
缩略图
设置应用设置myContainerName
.但在我们的代码中我们可以看到它连接到 Storage account created for Function app使用
AzureWebJobsStorage
并希望从应用设置THUMBNAIL_CONTAINER_NAME
获取容器名称。快速修复方法是替换
AzureWebJobsStorage
和THUMBNAIL_CONTAINER_NAME
,并为thumbnailWidth
设置常量。private static readonly string BLOB_STORAGE_CONNECTION_STRING = Environment.GetEnvironmentVariable("myblobstorage_STORAGE"); ... var thumbnailWidth = 100; var thumbContainerName = Environment.GetEnvironmentVariable("myContainerName");
当然,您可以选择在Azure门户的应用程序设置中添加
THUMBNAIL_WIDTH
。
重新发布,一切都应该正常。
关于c# - 由 Blob 存储上的 EventGrid 触发的 Azure 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53313094/