Azure Storage MD5 calculation does not match existing property

I am trying to pass Azure Storage Lure through ashx. In blockBlob.DownloadToStream (memoryStream), it throws the following exception: Microsoft.WindowsAzure.Storage.StorageException: Calculated MD5 does not match existing property

I know that he found the correct blob. If I put a container and a path that doesn't exist, it gives me an exception 404 instead.

I have Googled for tips on what might cause this error, but nothing useful comes up. Does anyone have any thoughts on what might be causing this? Over the past couple of days, I have rewritten this code in several different ways, but it always dies in DownloadToStream.

 using Microsoft.WindowsAzure; using Microsoft.WindowsAzure.Storage; using Microsoft.WindowsAzure.Storage.Auth; using Microsoft.WindowsAzure.Storage.Blob; public void ProcessRequest(HttpContext context) { // Retrieve storage account from connection string. Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(Microsoft.WindowsAzure.CloudConfigurationManager.GetSetting("StorageConnectionString")); // Create the blob client. CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); // Retrieve reference to a previously created container. CloudBlobContainer container = blobClient.GetContainerReference("gmt"); // Retrieve reference to blob named "articles/142/222.jpg". CloudBlockBlob blockBlob = container.GetBlockBlobReference("articles/142/222.jpg"); using (var memoryStream = new MemoryStream()) { blockBlob.DownloadToStream(memoryStream); byte[] photoByte = ReadFully(memoryStream); context.Response.Clear(); context.Response.ContentType = "image/jpeg"; context.Response.OutputStream.Write(photoByte, 0, photoByte.Length); } } public static byte[] ReadFully(Stream input) { input.Position = 0; using (MemoryStream ms = new MemoryStream()) { input.CopyTo(ms); return ms.ToArray(); } } 
+11
c # azure azure-storage
source share
2 answers

I was able to recreate the problem you are facing. This happens if the Content MD5 blob property is somehow damaged. I had a blob with some MD5 content (that was correct). Then I programmatically changed MD5 to a different value (which is wrong). Now, when I call the DownloadToStream () method in the blob, I get exactly the same error.

You can work around this check by setting DisableContentMD5Validation to true in BlobRequestOptions , as shown in the code below:

  BlobRequestOptions options = new BlobRequestOptions() { DisableContentMD5Validation = true, }; blockBlob.DownloadToStream(memoryStream, null, options); 

Try it and it should work.

On a side note, you can change your ReadFully method. You will need to move the input stream pointer to the beginning.

  public static byte[] ReadFully(Stream input) { input.Position = 0;//Positioning it to the top of stream. using (MemoryStream ms = new MemoryStream()) { input.CopyTo(ms); return ms.ToArray(); } } 
+6
source share

I had this problem in my local DEV environment. And it looks like the db AzureStorageEmulator messed up.

Solution (for local env!):

  • reset the database emulator (e.g. AzureStorageEmulatorDb57 )
  • run AzureStorageEmulator.exe init -sqlinstance . (you may need to configure the instance name)
  • run AzureStorageEmulator.exe start
  • restart the application so that it receives a new handler for the emulator
0
source share

All Articles