2

次のコードと出力を指定すると、このファイルをダウンロードしようとするたびに、このファイルに対して同じ例外が発生します。

md5 検証なしでダウンロードしてコンテンツを確認すると、ファイルに問題がないため、ブロブ メタデータの md5 プロパティ値が正しくないのではないかと疑っています。

そもそもどうすれば無効になるのかを理解しようとしています。ファイルのアップロード時にこのプロパティを設定するのは、Azure BLOB ストレージ内部ではありませんか?

解決策として 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 をダウンロードして計算し、ブロブのプロパティ値を更新します。

4

1 に答える 1