【发布时间】:2017-01-23 15:42:57
【问题描述】:
给出以下代码和输出,每次我尝试下载该文件时都会遇到相同的异常。
如果我在没有 md5 验证的情况下下载它并检查内容,则文件没有任何问题,因此我怀疑 blob 元数据上的 md5 属性值不正确。
我首先想弄清楚它是如何变得无效的。上传文件时设置此属性的不是azure blob storage internal吗?
我不想将 DisableContentMD5Validation 作为解决方案。
(ps.我首先使用Couldberry Explorer上传文件)
static void Main(string[] args)
{
{
try
{
var client = account.CreateCloudBlobClient();
var container = client.GetContainerReference("algorithms");
var blob = container.GetBlockBlobReference("SInnovations.Algorithms/SInnovations.Algorithms.FootprintFinder.1.0.0-pre-20140430.zip");
blob.FetchAttributes();
Console.WriteLine(blob.Properties.ContentMD5);
blob.DownloadToFile("c:\\dev\\test.zip", System.IO.FileMode.Create);
}
catch (StorageException ex)
{
if (ex.Message == "Calculated MD5 does not match existing property")
{
Console.WriteLine("Calculated MD5 does not match existing property");
}
}
}
{
var client = account.CreateCloudBlobClient();
var container = client.GetContainerReference("algorithms");
var blob = container.GetBlockBlobReference("SInnovations.Algorithms/SInnovations.Algorithms.FootprintFinder.1.0.0-pre-20140430.zip");
blob.FetchAttributes();
Console.WriteLine(blob.Properties.ContentMD5);
blob.DownloadToFile("c:\\dev\\test.zip", System.IO.FileMode.Create,null,new BlobRequestOptions()
{
DisableContentMD5Validation = true,
});
using (var md5 = MD5.Create())
{
using (var stream = File.OpenRead("c:\\dev\\test.zip"))
{
Console.WriteLine(md5.ComputeHash(stream));
}
}
}
}
}
给出这个输出
RH4EqqbthSm24KPgZ2VSGQ==
Calculated MD5 does not match existing property
RH4EqqbthSm24KPgZ2VSGQ==
System.Byte[]
Press any key to continue . . .
不好的例子,本地文件md5实际上是Hv+nQRNCPQnvy4WU9+qaQA==。
结论该属性在某些时候必须设置错误。
解决方案。下载并计算md5并更新blob的属性值。
【问题讨论】:
-
会不会是Cloudberry Explorer的MD5设置错误?
-
也许吧。用一些有趣的信息更新问题。 2秒
-
你能解释一下为什么在下载文件并计算 MD5 时,它与存储在 headers 中的匹配,但在没有禁用验证时仍然失败
-
文件有多大?我也可以使用大约那个大小的文件来尝试一下。
-
5360557 字节。但它只是我的 blob 存储中的一些文件。其他工作正常。
标签: azure cloudberry