Poul K. Sørensen
Poul K. Sørensen

Reputation: 17530

AzureBlobStorage : Calculated MD5 does not match existing property

Give the following code and output, i get the same exception for this file each time i try to download it.

If I download it without md5 validation and check the content, there is nothing wrong with the file so I am suspecting that the md5 property value is incorrect on the blobs metadata.

I am trying to figure out how it could become invalid in the first place. Is it not azure blob storage internal that sets this property when files are uploaded?

I dont want to DisableContentMD5Validation as a solution.

(ps. i used Couldberry Explorer to upload the file in the first place)

     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));
                }
            }

        }
    }
}

gives this output

RH4EqqbthSm24KPgZ2VSGQ==
Calculated MD5 does not match existing property
RH4EqqbthSm24KPgZ2VSGQ==
System.Byte[]
Press any key to continue . . .

Bad example, the local files md5 is infact, Hv+nQRNCPQnvy4WU9+qaQA==.

Conclussion the property must be set wrong at some point.

Solution. Download and calculate md5 and update property value of the blob.

Upvotes: 2

Views: 3298

Answers (1)

Martijn
Martijn

Reputation: 1390

I have experienced the same problem, with files that were uploaded through CloudBerry Storage Explorer (2.4.0.163). I uploaded the same files via the Azure Portal and The Azure Storage Explorer (http://storageexplorer.com/) and didn't experience the same issue (content corruption or md5 mismatch).

Upvotes: 0

Related Questions