由Blob存储上的EventGrid触发的Azure函数 [英] Azure Function triggered by EventGrid on Blob Storage
问题描述
I have followed the Microsoft tutorial to process event based on blob being created in Azure storage.
事件正在触发,但是由于EventGrid事件未填充输入流参数,所以绕过了处理图像的事件代码.这应该通过Blob(图像文件)的路径进行处理.
The event is firing but the event code to process the image is bypassed as the input stream parameter is not being populated by the EventGrid event. This should be passing through the path of the blob (image file) to process.
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,
推荐答案
该教程适用于 csx文件在谈论功能代码时.但是现在项目链接指向v2预编译的代码,当我们严格按照教程进行操作时,对代码的更改可能会导致问题.
The tutorial works for v1 c# script function as you can see it mentions csx file when talking about function code. But now the project link points to v2 pre-compiled code, changes in the code could cause problem when we follow the tutorial strictly.
让我们通过两个步骤解决不一致问题.
Let's fix the inconsistency with two steps.
-
关键是功能未连接到由于我们已经在
Since we have created an app setting
myblobstorage_STORAGE
in this step, we only have to add it in our function code.public static async Task Run( [EventGridTrigger]EventGridEvent eventGridEvent, [Blob("{data.url}", FileAccess.Read, Connection = "myblobstorage_STORAGE")] Stream input, ILogger log)
-
在同一步骤中,教程将为在
thumbnails设置应用程序设置 myContainerName
/storage/blobs/storage-upload-process-images?tabs = net#create-blob-storage-containers"rel =" nofollow noreferrer>第1部分. In the same step, tutorial sets an app setting
myContainerName
for containerthumbnails
created in Blob Storage Account in part1.But in our code we can see it connects to the Storage account created for Function app with
AzureWebJobsStorage
and wants to get container name from app settingTHUMBNAIL_CONTAINER_NAME
.快速解决方案是替换
AzureWebJobsStorage
和THUMBNAIL_CONTAINER_NAME
,并为thumbnailWidth
设置常量.The quick fix is to replace
AzureWebJobsStorage
andTHUMBNAIL_CONTAINER_NAME
, and set a constant forthumbnailWidth
.private static readonly string BLOB_STORAGE_CONNECTION_STRING = Environment.GetEnvironmentVariable("myblobstorage_STORAGE"); ... var thumbnailWidth = 100; var thumbContainerName = Environment.GetEnvironmentVariable("myContainerName");
当然,您可以选择在Azure门户的应用程序设置"中添加
THUMBNAIL_WIDTH
.Of course you could choose to add
THUMBNAIL_WIDTH
in Application settings of Azure portal.重新发布,一切正常.
这篇关于由Blob存储上的EventGrid触发的Azure函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!