2
votes

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.

1
Could it be that Cloudberry Explorer is setting the MD5 incorrectly?Gaurav Mantri
maybe. updating question with some interesting info. 2secPoul K. Sørensen
Can you explain why when downloading the file and calculates the MD5 its matches the one stored in headers, but it still fails when not having disabled validationPoul K. Sørensen
How big is the file? I might try it on my end as well using a file of approximately that size.Gaurav Mantri
5360557 bytes. But its just some of the files in my blob storage. Others works fine.Poul K. Sørensen

1 Answers

0
votes

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).