【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 数据的服务,通过无结构化的设计提供键/属性存储. 因为表存储无固定的数据结构要求,因此可以很容易地随着应用程序需求的发展使数据适 ...
随机推荐
- K3S +Helm+NFS最小化测试安装部署只需十分钟
作者:郝建伟 k3s 简介 官方文档:k3s 什么是k3s k3s 是一个轻量级的 Kubernetes 发行版 它针对边缘计算.物联网等场景进行了高度优化. k3s 有以下增强功能: 打包为单个二进 ...
- 手撕Vue-实现计算属性
前言 经过上一篇的学习, 完成了将数据代理到了 Nue 的实例上方,这个我们已经撕完了.接下来要实现的是计算属性,计算属性的实现原理是通过 Object.defineProperty() 来实现的,我 ...
- 数据挖掘机器学习[五]---汽车交易价格预测详细版本{模型融合(Stacking、Blending、Bagging和Boosting)}
题目出自阿里天池赛题链接:零基础入门数据挖掘 - 二手车交易价格预测-天池大赛-阿里云天池 相关文章: 特征工程详解及实战项目[参考] 数据挖掘---汽车车交易价格预测[一](测评指标:EDA) 数据 ...
- C/C++ 常见数组排序算法
本文介绍了几种常见的排序算法的实现,包括冒泡排序.选择排序.插入排序.希尔排序.归并排序和快速排序.冒泡排序通过多次遍历数组,比较并交换相邻元素,逐步将较小元素"浮"到数组顶端,时 ...
- Pdfium.Net.Free 一个免费的Pdfium的 .net包装器--创建字符子集
项目地址: Pdfium.Net:https://github.com/1000374/Pdfium.Net PdfiumViewer:https://github.com/1000374/Pdfiu ...
- 予力八六三软件应用现代化,提升DevSecOps效能,探索交付之路
本文分享自华为云社区<予力八六三软件应用现代化,提升DevSecOps效能,探索全球交付之路>,作者: HuaweiCloudDeveloper. 来源:<华为云DTSE>期刊 ...
- sed文本处理工具常见用法
sed的全称是stream editor, 表示它是一个流编译器.可以处理文本内容和终端命令的流标准输出,对文本做查找,替换,插入,删除操作. 它是把文件中的内容逐行copy到缓冲区,然后在缓冲区中进 ...
- 程序设计实验第一学期期末考试复习用源代码【C语言深度解剖】【超详细注释】
有关此篇 在这里博主先告诉大家,博主在学校学的C语言课本是<谭浩强的C语言>那这本红色的书. 博主到期末阶段是学到了结构体那一章,下面是博主的复习代码,是一些比较有编程思想的一些源代码,博 ...
- [JVM] Java内存分配
Java内存分配 程序计数器 程序计数器是一块较小的内存区域,作用可以看做是当前线程执行的字节码的位置指示器.分支.循环.跳转.异常处理和线程恢复等基础功能都需要依赖这个计算器来完成. 虚拟机栈 虚拟 ...
- JS leetcode 有序数组的平方 题解分析,灵活运用Math.pow与Math.abs方法
壹 ❀ 引 郁闷的周一,晚上来做一道简单的算法题提提神,题目来自leetcode977. 有序数组的平方,题目描述如下: 给定一个按非递减顺序排序的整数数组 A,返回每个数字的平方组成的新数组,要求也 ...