【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 数据的服务,通过无结构化的设计提供键/属性存储. 因为表存储无固定的数据结构要求,因此可以很容易地随着应用程序需求的发展使数据适 ...
随机推荐
- Docker 安装Oracle12c的镜像修改字符集 并且进行启动的简单过程
学习来自 昨天晚上转帖的文章 这里面添加一些自己的内容 首先获取配置文件 git clone https://github.com/oracle/docker-images.git 获取之后比较容易了 ...
- echarts更改x和y轴的颜色
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- echarts控制柱状图柱条的宽度
barWidth属性 series: [{ name: '销量', type: 'bar', barWidth : 30,//柱图宽度 data: [5, 20, 36, 10, 10, 20] }]
- 【代码片段】fasthttp 中的输出使用 gzip 压缩
作者:张富春(ahfuzhang),转载时请注明作者和引用链接,谢谢! cnblogs博客 zhihu Github 公众号:一本正经的瞎扯 直接上代码: import ( "github. ...
- Dto中使用正则校验规则,保证传入数据的正确性
使用RegularExpression
- 手撕Vue-数据驱动界面改变中
经过上一篇的介绍,已经实现了观察者模式的基本内容,接下来要完成的就是将上一篇的发布订阅模式运用到 Nue 中,实现数据驱动界面改变. 在监听数据变化的章节当中,根据指定的区域和数据去编译渲染界面 这个 ...
- 物联网浏览器(IoTBrowser)-电子秤模块及二次驱动开发
本章介绍电子秤模块的示例功能以及二次开发称重驱动的代码,二次开发以顶尖OS2型号驱动为示例,实现方式与物联网浏览器(IoTBrowser)-顶尖OS2电子秤协议实现类似,不同的是电子秤只需要采集重量不 ...
- 2.1 C/C++ 使用数组与指针
C/C++语言是一种通用的编程语言,具有高效.灵活和可移植等特点.C语言主要用于系统编程,如操作系统.编译器.数据库等:C语言是C语言的扩展,增加了面向对象编程的特性,适用于大型软件系统.图形用户界面 ...
- 位图|布隆过滤器模拟实现|STL源码剖析系列|手撕STL
今天博主给大家带来位图和布隆过滤器的模拟实现. 前言 那么这里博主先安利一下一些干货满满的专栏啦! 手撕数据结构https://blog.csdn.net/yu_cblog/category_1149 ...
- CF813E Army Creation 题解
题目链接:CF 或者 洛谷 并不是很难的题,关于颜色数量类问题,那么很显然,沿用经典的 "HH的项链" 思想去思考问题.由于涉及到了 \(k\) 个数的限制,我们观察到如果一个数在 ...