I'm trying to pass an Azure Storage blob through an ashx. On the blockBlob.DownloadToStream(memoryStream) it's throwing the following Exception: Microsoft.WindowsAzure.Storage.StorageException: Calculated MD5 does not match existing property
I know it's finding the correct blob. If I put in a container and path that don't exist then it gives me a 404 exception instead.
I've Googled for hints on what might be causing this error but nothing useful is coming up. Does anyone have any thoughts on what might be causing this? I've rewritten this code a couple different ways over the last couple days but it always dies on 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();
}
}