【问题标题】:The remote server returned an error: (412) The condition specified using HTTP conditional header(s) is not met..远程服务器返回错误:(412) The condition specified using HTTP conditional header(s) is not met..
【发布时间】:2016-11-30 18:16:53
【问题描述】:

我正在尝试使用 DownloadText() 下载 Azure Append Blob 的内容。该函数偶尔会抛出异常:

远程服务器返回错误:(412) The condition specified using HTTP conditional header(s) is not met..

虽然我没有编写任何代码来管理并发,所以应该应用默认的“Last Wins”逻辑。正在从 Web 应用程序和 API 访问 Blob 存储,但只是偶尔在 Web 应用程序中引发此异常。

【问题讨论】:

    标签: c# asp.net .net azure azure-blob-storage


    【解决方案1】:

    根据错误消息,尝试下载 blob 内容时似乎已更改 blob 内容。如果 blob 更改,则 blob 的 ETag 将自动更改。请尝试使用以下代码检查并弄清楚。有关存储条件操作的更多详细信息,请参阅document

           CloudAppendBlob appendBlob = container.GetAppendBlobReference("myAppendBlob");
            appendBlob.FetchAttributes();
            var etag = appendBlob.Properties.ETag;
            try
            {
                appendBlob.DownloadText(Encoding.UTF8, AccessCondition.GenerateIfMatchCondition(etag));
            }
            catch (Exception)
            {
                appendBlob.FetchAttributes();
                var updateEtag = appendBlob.Properties.ETag;
                Console.WriteLine($"Original:{etag},Updated:{updateEtag}");
                //To Do list
                //appendBlob.DownloadText(Encoding.UTF8, AccessCondition.GenerateIfMatchCondition(updateEtag));
            }
    

    【讨论】:

    • 感谢您的回答。尝试同时从多个 AJAX 调用中使用 DownloadText() 时会发生这种情况吗?
    • 如果资源被多个应用访问或更改,请尝试确保原始文件没有更改。
    猜你喜欢
    • 1970-01-01
    • 2012-09-20
    • 2014-08-22
    • 2018-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多