Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Storage: how to read blob data and properties on a single access?

I need to read blob data quickly. However it seems that FetchAttributes() and OpenRead() methods each do an access to storage. My blobs are really small, so I wish I could read everything in a single access. Is that possible?

The only attribute I'm interested is ETag. I want it to do efficient and conflict-aware updates and deletes to blob contents.

like image 522
fernacolo Avatar asked May 05 '14 20:05

fernacolo


People also ask

How do I read blob metadata?

To retrieve metadata, call the GetProperties or GetPropertiesAsync method on your blob or container to populate the Metadata collection, then read the values, as shown in the example below. The GetProperties methods retrieve blob properties and metadata in a single call.

How do I access Azure blob data?

Objects in Blob storage can be accessed from anywhere in the world via HTTP or HTTPS. Users or client applications can access blobs via URLs, the Azure Storage REST API, Azure PowerShell, Azure CLI, or an Azure Storage client library. The storage client libraries are available for multiple languages, including .


2 Answers

According to MSDN you're stuck with a 2 step process:

"Retrieving property and metadata values for a resource is a two-step process. Before you can read these values, you must explicitly fetch them on your CloudBlobContainer, CloudBlockBlob, or CloudPageBlob objects. To fetch properties and metadata synchronously, call FetchAttributes on the container or blob; to fetch them asynchronously, call BeginFetchAttributes and EndFetchAttributes."

like image 76
Haney Avatar answered Sep 25 '22 14:09

Haney


Assuming you know the type of your blob and you want to download all properties, metadata, and the contents of the blob, you can directly call DownloadToStream.

DownloadToStream internally makes a Get Blob request, which returns blob's properties and metadata.

like image 27
Serdar Ozler Avatar answered Sep 23 '22 14:09

Serdar Ozler