c# - 获取 Azure BlockBlob 内容类型

标签 c# azure blob containers

我正在尝试从 Azure BlockBlob 获取“内容类型”。好像不行。

enter image description here

如您所见,该文件的“内容类型”是“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");

它总是返回空,如下图所示:

enter image description here

最佳答案

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/

相关文章:

c# - 十进制值舍入 .99

c# - 函数内的 if 语句

c# - 如何设置相机与缩放物体的距离?

c# - GPS 套接字通信 (CONCOX)

Azure VM 带宽限制

azure - 从 Azure User Graph 获取唯一用户位置的方法

java - 将大型文本文件上传到 DB2 CLOB 字段

powershell - 部署 ARM 模板时使用 PowerShell 覆盖parameters.json 文件中的参数

c# - 在 MySQL 中加密,在 C# 中解密

c# - 从数据库中检索 BLOB 并将其保存在本地