2

I need to fetch the metadata for an Azure blob if it exists and would like to achieve this with minimal REST calls (by the storage SDK to the storage service)

I know I can do something like

  • CloudBlockBlob.ExistsAsync() and then
  • CloudBlockBlob.FetchAttributesAsync() if the blob exists

I tried to combine these 2 calls into one

  • CloudBlockBlob.FetchAttributesAsync(AccessCondition.GenerateIfExistsCondition(),new BlobRequestOptions(), new OperationContext());

Docs on 'AccessCondition.GenerateIfExistsCondition()' say -

Constructs an access condition such that an operation will be performed only if the resource exists.

but it still fails with a 404 not found.

Any idea if what I want to achieve is even possible and what I might be doing wrong?

1 Answer 1

1

Looking at the documentation for the action: https://learn.microsoft.com/en-us/rest/api/storageservices/get-blob-properties.

It's basically a HEAD request to the blob, and there is no mention of If-Match etc. for headers.

So I think the most optimal way of doing it is just calling FetchAttributesAsync. If that causes a 404, then the blob did not exist. It only does 1 HTTP request.

Sign up to request clarification or add additional context in comments.

4 Comments

Would need to wrap it in a try catch. Wanted to avoid generating exceptions as far as possible 🙂
Right, that would indeed be nice. If you could tell the Storage SDK to not throw, but return null if not found etc..
I did check the decomiled code. It adds the if-match header with a value of '*'. Don't know how that's processed by the server though
The AccessCondition can be specified so you can specify a lease id if you have acquired a lease on the blob.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.