简体   繁体   English

Azure 函数在 blob 触发器期间找不到 blob

[英]Azure function cannot find blob during blob trigger

There is an Azure function that is triggered when HTML files are placed into Azure blob storage.The function opens the HTML file, and transforms it into JSON.将 HTML 文件放入 Azure blob 存储时会触发一个 Azure 函数。该函数打开 HTML 文件,并将其转换为 JSON。 There is a small percentage of triggered files (less than 1%), that result in the following exception:有一小部分触发文件(小于 1%)会导致以下异常:

Microsoft.WindowsAzure.Storage.StorageException Microsoft.WindowsAzure.Storage.StorageException

There does happen to be a second function triggered by the placement of the blob that changes the files content type, but I am not sure if this is effecting the first function's ability to also open the file.确实有第二个函数由 blob 的放置触发,该函数更改了文件的内容类型,但我不确定这是否会影响第一个函数打开文件的能力。

What can be done to allow the Azure functions to correctly process the HTML files without throwing this type of exception?如何让 Azure 函数正确处理 HTML 文件而不引发此类异常?

Exception properties :异常属性

Message: Exception while executing function: [Function name here] The condition specified using HTTP conditional header(s) is not met.消息:执行函数时出现异常:[此处的函数名称] 不满足使用 HTTP 条件标头指定的条件。

Exception type: Microsoft.WindowsAzure.Storage.StorageException异常类型:Microsoft.WindowsAzure.Storage.StorageException

Failed method: HtmlAgilityPack.HtmlDocument.Load失败的方法:HtmlAgilityPack.HtmlDocument.Load

Exception type: Microsoft.WindowsAzure.Storage.StorageException异常类型:Microsoft.WindowsAzure.Storage.StorageException

Function 1 (supporting methods, class, and namespace omitted for brevity):函数 1 (为简洁起见省略了支持的方法、类和命名空间):

using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using HtmlAgilityPack;
using System.Threading.Tasks;

[FunctionName("Function name")]
public static async Task Run([BlobTrigger("container-name/html/{name}", Connection = "ConnectionString")]Stream myBlob, ILogger log, Binder binder)
{
    var doc = new HtmlDocument();
    doc.Load(myBlob);
    var form = doc.DocumentNode.SelectSingleNode("//form");
    var elements = form.SelectNodes("//input");
    CustomType MyObject = BuildObject(elements);

    var attributes = new Attribute[]
    {
        new BlobAttribute("container-name/json/" + MyObject.ID + ".json"),
        new StorageAccountAttribute("ConnectionString")
    };

    using (var writer = await binder.BindAsync<TextWriter>(attributes))
    {
        writer.Write(BuildJSON(MyObject));
    }

}

Function 2 same trigger but in a different function and it's own .cs file.功能 2相同的触发器,但在不同的功能中,它是自己的 .cs 文件。 Class and namespace omitted for brevity:为简洁起见省略了类和命名空间:

using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;
using Microsoft.WindowsAzure.Storage.Blob;

[FunctionName("Function name")]
public static async Task Run([BlobTrigger("container-name/html/{name}", Connection = "ConnectionString")]ICloudBlob myBlob)
{
    if (myBlob.Properties.ContentType == "text/html; charset=utf-8")
    return;

    myBlob.Properties.ContentType = "text/html; charset=utf-8";
    await myBlob.SetPropertiesAsync();
}

I think your error should appear like this: Funtion1 retrieves the blob, and then function2's operation on the blob causes the change of Etag.我认为你的错误应该是这样的:Funtion1 检索到 blob,然后 function2 对 blob 的操作导致 Etag 的变化。 Then function1 tries to load the retrieved blob, but finds that the Etag has changed, so it returns to you abnormal.然后function1尝试加载检索到的blob,却发现Etag发生了变化,所以异常返回给你。

If the resource is accessed or changed by multiple apps, please have a try to make sure the orginal files are not changed.如果资源被多个应用程序访问或更改,请尝试确保原始文件没有被更改。 Otherwise the Etag of the blob will be changed automatically.否则 blob 的 Etag 将自动更改。

Azure Storage blob use 'strong Etag validation'. Azure 存储 blob 使用“强 Etag 验证”。 the content of the two resource representations must be byte-for-byte identical and that all other entity fields (such as Content-Language) are also unchanged.两个资源表示的内容必须逐字节相同,并且所有其他实体字段(例如 Content-Language)也保持不变。

Please refer to this: https://www.microsoftpressstore.com/articles/article.aspx?p=2224058&seqNum=12请参考: https : //www.microsoftpressstore.com/articles/article.aspx?p=2224058&seqNum=12

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM