alwayslearning
alwayslearning

Reputation: 4633

Fetch Azure blob metadata only if the blob exists

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

I tried to combine these 2 calls into one

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?

Upvotes: 2

Views: 1638

Answers (1)

juunas
juunas

Reputation: 58898

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.

Upvotes: 1

Related Questions