简体   繁体   中英

Azure Storage - Download a blob with conditions

I've been having trouble assigning read conditions on blobs when trying to download them when using the Azure Storage SDK .

Basically, what I am trying to do goes like this:

  1. Upload a blob ( WORKS )
  2. Download the blob ( WORKS )
  3. Get the Etag of the blob with blobRef.GetProperties().Etag ( WORKS )
  4. Use the Etag to try to download the blob again expecting a RequestFailedException e where the e.ErrorCode == ConditionNotMet ( FAILS )

This is the code:

var condition = new Azure.Storage.Blobs.Models.BlobRequestConditions
{
    IfNoneMatch = new Azure.ETag(previousEtagString),
};

//blobRef is a valid instance of Azure.Storage.Blobs.BlobClient
//target is the filePath

blobRef.DownloadTo(target, conditions: condition); // this should throw RequestFailedException

Notes:

  1. When I try to compare the Etag fetched from step 3 (which is converted to a string) with the one I am sending in step 4, it returns they are the same blobRef.GetProperties().Etag == new Azure.Etag(blobRef.GetProperties().Etag.ToString()) -> true

  2. I also opened the question at the GitHub Repo

  3. Passing test cases with v11:

     var blobRef = _blobContainer.GetBlockBlobReference(identifier); blobRef.DownloadTo(target, AccessCondition.GenerateIfNoneMatchCondition(stringEtag)); //throws StorageException
  4. Just noticed that the blob downloaded the second time, does not contain any data. It's empty. The first one has data. Are the read conditions partially working, but not throwing the exception?

在此处输入图像描述

Thanks

Use the Etag to try to download the blob again expecting a RequestFailedException e where the e.ErrorCode == ConditionNotMet

This is not the expected behavior because Etag only changes when a blob is updated.

If a blob is not updated, Etag value remains the same. So if you do not update the blob, you can perform a conditional download multiple times without getting the precondition failure error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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