带有blobtrigger的Azure函数-更新元数据 [英] Azure function with blobtrigger - update metadata

查看:69
本文介绍了带有blobtrigger的Azure函数-更新元数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个示例或IP,用于在上传Blob时更新其元数据.感谢所有帮助.

I am looking for a sample or IP for updating a blob's metadata when it is uploaded. All help is appreciated.

我具有以下功能:

public static void Run([BlobTrigger("types/{name}", Connection = "StorageConnection")]Stream myBlob, string name, ILogger log)
{
}

推荐答案

您可以使用触发器获取ICloudBlob而不是流.
查看官方文档关于Azure函数的blob触发器.

You can use the trigger to get the ICloudBlob instead of the stream.
Check the official documentation on blob triggers for Azure Functions.

基本上,您的代码将如下所示:

Basically, your code will look something like this:

public static void Run(
    [BlobTrigger("types/{name}", Connection = "StorageConnection")] ICloudBlob myBlob, 
    string name, 
    ILogger log)
{
    if (blobTrigger.Metadata.ContainsKey("MyKey"))
        return;

    blobTrigger.Metadata["MyKey"] = "MyValue";
    await blobTrigger.SetMetadataAsync();
}

但是有一个问题.更新元数据后,基本上您将再次上传该Blob,这又将再次触发您的功能.

There is an issue though. After you update your metadata, you are basically uploading the blob again, which in turn, will trigger your function again.

我添加了一个简单的检查,以查看是否已经添加了我的元数据键,以避免无限循环.
当然,您可能会以自己的方式知道自己是否只是更新元数据的人.最坏的情况是,您必须使用自己的标志来指示上载是通过您的函数进行的.

I've added a simple check to see if my metadata key was already added to avoid an infinite loop.
Of course, you will probably have your own way of knowing if you are the one who just updated the metadata or not. Worst case scenario, you'll have to use your own flag to indicate that the upload occurred from your function.

希望它会有所帮助. :)

Hope it helps. :)

这篇关于带有blobtrigger的Azure函数-更新元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆