问题描述
通过.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($"tt ContentLanguage: {properties.ContentLanguage}");
Console.WriteLine($"tt ContentType: {properties.ContentType}");
Console.WriteLine($"tt CreatedOn: {properties.CreatedOn}");
Console.WriteLine($"tt LastModified: {properties.LastModified}");
Console.WriteLine($"tt ContentHash: {FormatHashValue(properties.ContentH服务器托管网ash)}");
Console.WriteLine($"tt ContentMD5: {Convert.ToBase64String(properties.ContentHash)}");
}
}
public static string FormatHashValue(byte[] contentHash)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i
参考资料
如何调用 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
当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.fwqtg.net
针对MobPush智能推送服务在使用过程中可能出现的问题,本文为各位开发者们服务器托管网带来了针对MobPush安卓端推送问题的解决办法。 TCP在线推送排查 排查TCP在线收不到推送时,我们先通过客户端的RegistrationId接口获取设备的唯一标识 示…