2016-11-18 92 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