I'm trying to find an more elegant way of checking to see if there is anything in the blob storage I've created.
I have a service that reads from blob storage. I basically need to be sure that when my service is restarted, it will check if there is anything in blob to read and process before running normally.
I can't seem to find a method that checks if the blockblob is empty. I came up with a way to do this, but I would like to know if there is a more elegant way of doing this:
here is my solution, just check if you were able to download anything. Sure it works..
public bool IsBlobEmpty()
{
string text;
using (var memoryStream = new MemoryStream())
{
blockBlob.DownloadToStream(memoryStream);
text = System.Text.Encoding.UTF8.GetString(memoryStream.ToArray());
if (text.Length > 0)
{
return false;
}
}
return true;
}
You can use the Azure Storage Blob APIs to get the metadata information of the blob and check for its size - https://msdn.microsoft.com/en-us/library/azure/dd179394.aspx
Response headers from the server contains a Content-Length property