Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Azure BlockBlob Content Type

I am trying to get "Content Type" from Azure BlockBlob. It's seems like not work.

enter image description here

This file's "Content Type" is "image/jpeg" as you see.

            var cloudConn = System.Configuration.ConfigurationManager.ConnectionStrings["StoreAccount"].ConnectionString;

            var storageAccount = CloudStorageAccount.Parse(cloudConn);
            var blobClient = storageAccount.CreateCloudBlobClient();

            var container = blobClient.GetContainerReference("containername");

            var blocBlob = container.GetBlockBlobReference("009fc790-2e8e-4b59-bbae-3b5e2e845a3b");

And it always returns empty as you see in this picture:

enter image description here

like image 442
user3838168 Avatar asked Dec 08 '22 20:12

user3838168


1 Answers

var blocBlob = container.GetBlockBlobReference("009fc790-2e8e-4b59-bbae-3b5e2e845a3b");

Code above simply creates an instance of CloudBlockBlob and initializes it with default properties. You would need to fetch the blob properties (as mentioned in the answer included in the comment above) and then you will see the properties filled up. To fetch blob properties, you would need to call FetchAttributes() method.

var blocBlob = container.GetBlockBlobReference("009fc790-2e8e-4b59-bbae-3b5e2e845a3b");
blocBlob.FetchAttributes();

Then you should be able to see the content type property of the blob.

like image 55
Gaurav Mantri Avatar answered Dec 20 '22 17:12

Gaurav Mantri