2016-11-18 93 views
2

我試圖從Azure BlockBlob獲取「內容類型」。這似乎沒有工作。獲取Azure BlockBlob內容類型

enter image description here

該文件的 「內容類型」 爲 「圖像/ JPEG」 你看。

  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"); 

,你在這張照片看,它始終返回空:

enter image description here

+0

看到這個職位(RE:FetchAttributes ):http://stackoverflow.com/questions/22062648/getting-the-file-type-in​​-azure-storage –

回答

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

以上代碼只是創建的CloudBlockBlob實例,並使用默認屬性初始化。您需要獲取blob屬性(如上面評論中包含的答案中所述),然後您將看到填充的屬性。要獲取blob屬性,您需要調用FetchAttributes()方法。

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

然後你應該能夠看到blob的內容類型屬性。

1

爲了讓你必須首先獲取屬性的BLOB屬性:

blob.FetchAttributes() 

然後你就可以得到內容類型通過:

blob.Properties.ContentType