【Azure Storage Blob】如何通过.NET Azure Storage Blobs SDK获取到Blob的MD5值呢?
问题描述
通过.NET Azure Storage Blobs SDK , 获取Blob的MD5值,查看了Azure操作手册中,介绍可以使用 blob.Properties.ContentMD5 属性。
//blob 文件测试
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference("file");
CloudBlockBlob blob = container.GetBlockBlobReference(@"image-03.jpg");
blob.UploadFromFile(filePath1, FileMode.OpenOrCreate);
Console.WriteLine("md5=" + blob.Properties.ContentMD5);
但是,在项目中,发现SDK更新后(Azure.Storage.Blobs 12.9.1)后,Properties中并没有ContentMD5属性?

问题解答
查看Blob Properties属性的源代码,发现没有了ContentMD5, 但是可以使用ContentHash。如果把ContentHash进行Base64编码后,它的结果就和Azure门户中的Content-MD5值一样:

示例代码如下:
static async Task GetBlobMD5Async(string connectionString,string containerName)
{
//// Create a BlobServiceClient object which will be used to create a container client
BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);
BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(containerName); Console.WriteLine("Listing blobs...");
// List all blobs in the container
await foreach (BlobItem blobItem in containerClient.GetBlobsAsync())
{
Console.WriteLine("\t" + blobItem.Name); BlobClient bclient = containerClient.GetBlobClient(blobItem.Name); // Get the blob properties
BlobProperties properties = await bclient.GetPropertiesAsync(); // Display some of the blob's property values
Console.WriteLine($"\t\t ContentLanguage: {properties.ContentLanguage}");
Console.WriteLine($"\t\t ContentType: {properties.ContentType}");
Console.WriteLine($"\t\t CreatedOn: {properties.CreatedOn}");
Console.WriteLine($"\t\t LastModified: {properties.LastModified}");
Console.WriteLine($"\t\t ContentHash: {FormatHashValue(properties.ContentHash)}");
Console.WriteLine($"\t\t ContentMD5: {Convert.ToBase64String(properties.ContentHash)}");
}
} public static string FormatHashValue(byte[] contentHash)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < contentHash.Length; i++)
{
sb.Append(contentHash[i].ToString("x2"));
}
return sb.ToString();
}
参考资料
如何调用 API 获取 Azure File 存储中文件的 MD5值:https://docs.azure.cn/zh-cn/articles/azure-operations-guide/storage/aog-storage-blob-file-md5
BlobProperties.ContentHash Property: https://learn.microsoft.com/en-us/dotnet/api/azure.storage.blobs.models.blobproperties.contenthash?view=azure-dotnet
Manage blob properties and metadata with .NET : https://learn.microsoft.com/en-us/azure/storage/blobs/storage-blob-properties-metadata#set-and-retrieve-properties
【Azure Storage Blob】如何通过.NET Azure Storage Blobs SDK获取到Blob的MD5值呢?的更多相关文章
- 如何获取Azure Storage Blob的MD5值
问题表述 直接使用CloudBlockBlob对象获取的Properties是空的,无法获取到对象的MD5值,后台并未进行属性值的填充 前提:blob属性本省包含md5值,某些方式上传的blob默认并 ...
- Azure Storage 系列(二) .NET Core Web 项目中操作 Blob 存储
一,引言 上一篇文章,我们介绍到在实际项目中系统会产生大量的日志文件,用户上传的头像等等,同时也介绍到可以使用Azure Blob Storage 来存储项目中的一些日志文件,用户头像,用户视频等等. ...
- Azure系列2.1 —— com.microsoft.azure.storage.blob
网上azure的资料较少,尤其是API,全是英文的,中文资料更是少之又少.这次由于公司项目需要使用Azure,所以对Azure的一些学习心得做下笔记,文中不正确地方请大家指正. Azure Blob ...
- [Windows Azure] How to use the Windows Azure Blob Storage Service in .NET
How to use the Windows Azure Blob Storage Service in .NET version 1.7 version 2.0 This guide will de ...
- 使用PowerShell创建Azure Storage的SAS Token访问Azure Blob文件
Azure的存储包含Storage Account.Container.Blob等具体的关系如下: 我们常用的blob存储,存放在Storage Account的Container里面. 目前有三种方 ...
- Azure Functions(二)集成 Azure Blob Storage 存储文件
一,引言 上一篇文章有介绍到什么是 SeverLess ,ServerLess 都有哪些特点,以及多云环境下 ServerLess 都有哪些解决方案.在这众多解决方案中就包括 Function App ...
- 【Azure 存储服务】代码版 Azure Storage Blob 生成 SAS (Shared Access Signature: 共享访问签名)
问题描述 在使用Azure存储服务,为了有效的保护Storage的Access Keys.可以使用另一种授权方式访问资源(Shared Access Signature: 共享访问签名), 它的好处可 ...
- 【Azure 存储服务】Java Azure Storage SDK V12使用Endpoint连接Blob Service遇见 The Azure Storage endpoint url is malformed
问题描述 使用Azure Storage Account的共享访问签名(Share Access Signature) 生成的终结点,连接时遇见 The Azure Storage endpoint ...
- Azure Functions(三)集成 Azure Queue Storage 存储消息
一,引言 接着上一篇文章继续介绍 Azure Functions,今天我们将尝试绑定 Queue Storage,将消息存储到 Queue 中,并且学会适用于 Azure Functions 的 Az ...
- 【Azure 存储服务】Python模块(azure.cosmosdb.table)直接对表存储(Storage Account Table)做操作示例
什么是表存储 Azure 表存储是一项用于在云中存储结构化 NoSQL 数据的服务,通过无结构化的设计提供键/属性存储. 因为表存储无固定的数据结构要求,因此可以很容易地随着应用程序需求的发展使数据适 ...
随机推荐
- Sysbench 开启超线程/关闭超线程以及容器运行数据库的性能损耗
Sysbench 开启超线程/关闭超线程性能损耗 摘要 Stress-NG 测试完之后 突然想 使用sysbenchen也进行一次压测 验证一把 超线程对数据的性能影响. 压测命令 ./sysbenc ...
- Find 查找并且展示最近24小时内创建的文件信息
1. 命令为: find /gscloud/tools/patchinstall/patchfiles/ -maxdepth 1 -mtime 1 |cut -c40- >/deploy/pat ...
- web字体小于12px的解决办法
大家都知道,web端的字体在正常情况下,最小只能够是12px; 但是有些时候,可能需要字体小于12px 那么如何解决这个办法了 可以使用css3的缩放属性scale 如果字体的大小是10px; 那么我 ...
- Linux 系统下查找文件命令
Linux 系统下查找文件命令,融合多部Linux经典著作,去除多余部分,保留实用部分. 查命令绝对路径: which用于查找并显示给定命令的绝对路径,环境变量中PATH参数也可以被查出来. [roo ...
- 解决Maven项目创建过慢问题
在创建时弹出Proerties位置添加键值对: archetypeCatalog internal idea 常用快捷键 Alt+回车 导入包,自动修正 Ctrl+N 查找类 Ctrl+Shift+N ...
- 利用 ASP.NET Core 开发单机应用
前言 现在是分布式微服务开发的时代,除了小工具和游戏之类刚需本地运行的程序已经很少见到纯单机应用.现在流行的Web应用由于物理隔离天然形成了分布式架构,核心业务由服务器运行,边缘业务由客户端运行.对于 ...
- Gitee API的使用|如何批量删除Gitee下的所有仓库
前言 那么这里博主先安利一些干货满满的专栏了! 首先是博主的高质量博客的汇总,这个专栏里面的博客,都是博主最最用心写的一部分,干货满满,希望对大家有帮助. 高质量博客汇总https://blog.cs ...
- auto_ptr|unique_ptr|shared_ptr|weak_ptr|你都搞明白了吗?
前言 那么这里博主先安利一些干货满满的专栏了! 首先是博主的高质量博客的汇总,这个专栏里面的博客,都是博主最最用心写的一部分,干货满满,希望对大家有帮助. 高质量干货博客汇总https://blog. ...
- 洛谷P1009 阶乘之和
捏妈第三节的题单名不是循环结构吗,直接出了第八节的高精度大数计算,紧急学习 对于较大数的加减乘除阶乘等,C/C++原生的数据类型是存储不了的(即便用longlong),直接计算会出现数据移除成负数的结 ...
- IIS的详细配置
一:配置默认文档 输入ip打开哪个页面是由默认文档设定的 1.打开IIS配置页面,点击网站.我们的默认站点已经启动,可以看到绑定的ip和网页的路径 2.选中Default Web Site,可以看到有 ...