Walaa El Kerdy
Walaa El Kerdy

Reputation: 31

The remote server returned an error: (412) The condition specified using HTTP conditional header(s) is not met..

I am trying to download the content of an Azure Append Blob using DownloadText(). The function is throwing an exception occasionally:

The remote server returned an error: (412) The condition specified using HTTP conditional header(s) is not met..

Although I did not write any code to manage concurrency, so the default 'Last Wins' logic should be applied. The blob storage is being accessed from a Web App and API but only throwing this exception in the web app occasionally.

Upvotes: 2

Views: 4309

Answers (1)

Tom Sun
Tom Sun

Reputation: 24539

According to the error message, it seems that blob content has been changed when try to download the blob content. The ETag of the blob will be changed automatically if the blob is changed. Please have a try to use the following code to check and figure it out. More detail info about the storage conditional operations, please refer to the 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));
        }

Upvotes: 4

Related Questions