2

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.

Poul K. Sørensen
  • 16,950
  • 21
  • 126
  • 283
  • Could it be that Cloudberry Explorer is setting the MD5 incorrectly? – Gaurav Mantri Jul 21 '14 at 09:51
  • maybe. updating question with some interesting info. 2sec – Poul K. Sørensen Jul 21 '14 at 09:59
  • 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 validation – Poul K. Sørensen Jul 21 '14 at 10:01
  • How big is the file? I might try it on my end as well using a file of approximately that size. – Gaurav Mantri Jul 21 '14 at 10:09
  • 5360557 bytes. But its just some of the files in my blob storage. Others works fine. – Poul K. Sørensen Jul 21 '14 at 10:11
  • I will try to copy the file to a new storage account and see if the file has same issues there. Will also try reuploading the file and see if it solves it. If i can persist the issue across those two tests I can provide the file for tests also. But past experience tell me as soon as i reupload or copy the file the problem goes away – Poul K. Sørensen Jul 21 '14 at 10:15

1 Answers1

0

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

Martijn
  • 1,379
  • 1
  • 10
  • 13
  • 1
    As I've been told Cloudberry doesn't calculate md5 on any stage, it just upload the data and this header is being generated by Azure. – Anton Zorin Jan 31 '17 at 15:43