Domanda

I have just updated my azure windows storage version to Version 3.0.2.0. I have had to update my code to suit the new version. This has mainly worked but I am having problems updating my code for downloading an image file to a byte array. I am trying:

    Dim storageAccount As CloudStorageAccount = CloudStorageAccount.Parse(
        CloudConfigurationManager.GetSetting("StorageConnectionString"))

    'Create the blob client.
    Dim blobClient As CloudBlobClient = storageAccount.CreateCloudBlobClient()

    'Retrieve reference to a previously created container.
    Dim container As CloudBlobContainer = blobClient.GetContainerReference("container")

    'Retrieve reference to a blob named "photo1.jpg".
    Dim blockBlob As CloudBlockBlob = container.GetBlockBlobReference("photo1.jpg")

    Try
        Dim byteData As Byte() = {}
        blockBlob.DownloadToByteArray(byteData, 0)
        context.Response.BinaryWrite(byteData)
    Catch ex As Exception
        CreateErrorLog(ex, "ProcessRequest")

    End Try

This fails with the error: "The remote server returned an error: (400) Bad request".

I am downloading the image to display it on a webpage. I am doing this by using an IHttpHandler. I have been unable to find any examples of the usage of DownloadToByteArray. Can anyone let me know the correct way to download my blob file.

È stato utile?

Soluzione

I've rechecked this and found that I was using the wrong container name. So the code is correct. I had assumed that the correct blob had been found because the code didn't fail on the line:

Dim blockBlob As CloudBlockBlob = container.GetBlockBlobReference("photo1.jpg")

but it can't have been because the container name was incorrect!

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top