我正在尝试从 Azure BlockBlob 获取“内容类型”。好像不行。
如您所见,该文件的“内容类型”是“image/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");
它总是返回空,如下图所示:
最佳答案
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 的内容类型属性。
关于c# - 获取 Azure BlockBlob 内容类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40679984/