1
votes

I am developing an Azure website, and I want to make use of Blob storage. I am using VS2013, Azure SDK 2.2. I have tried Azure Storage 2.1.0.4 from NuGet, I have tried using the latest 3.0.2.0 too. I have upgraded the emulator to the latest preview version 2.2.1, I was using 2.2.0 before.

My issue is, it doesnt matter if I point at the emulator or real storage, I get Bad Request 400 errors (invalid headers).

I set up a really simple form application, with a single button to make this easy.

private void button1_Click(object sender, EventArgs e)
{
   var account = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));

   CloudBlobClient blobClient = account.CreateCloudBlobClient();

   CloudBlobContainer container = blobClient.GetContainerReference("UserImages");    

   if (!container.Exists())
   {
      container.Create();
      container.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Off });
   }

}

Everything looks good until container.Exists() executes, and then I get an unhandled error (Bad Request 400). I have tried a few different operations and I get the same unhelpful message every time.

I am storing the Azure Connection string in the appSettings section, and in this simple example I have tried pointing at a real Storage Account, and the emulator, and I get the 400 error every time.

My config file has this:

<appSettings>
    <add key="StorageConnectionString" value="DefaultEndpointsProtocol=https;AccountName=[MyAccountName];AccountKey=[MYREALKEY]" />
</appSettings>

Using the Server Explorer in VS2013, I can happily connect to both the Emulator and real storage, and access Blob storage without issue.

This is effectively stopping me adding the ability to my site to upload files to the storage account.

Anyone else having this problem? As far as I know, I have tried older versions and the latest versions of the important components. I have always had SDK 2.2 though.

Any suggestions gratefully received.

For information, I followed this example, which I found in the Azure management portal: http://www.windowsazure.com/en-us/documentation/articles/storage-dotnet-how-to-use-blobs-20/

Thanks

Ian

2
Please convert your container name to lowercase and retry your request.Gaurav Mantri
can containers contains upper case letters? I thought they could not.Neil Thompson
That fixed the issue for REAL storage, but the emulator still throws 400 errors. <add key="StorageConnectionString" value="UseDevelopmentStorage=true" /> is my Emulator string.Ian Robertson
Is there any proper documentation I have missed, that seems like a schoolboy mistake, but I dont remember seeing rules on naming conventions etc.Ian Robertson

2 Answers

3
votes

To see naming rules, please check out this link: http://msdn.microsoft.com/en-us/library/windowsazure/dd135715.aspx. From this documentation page:

A container name must be a valid DNS name, conforming to the following naming rules:

  • Container names must start with a letter or number, and can contain only letters, numbers, and the dash (-) character.

  • Every dash (-) character must be immediately preceded and followed by a letter or number; consecutive dashes are not permitted in
    container names.

  • All letters in a container name must be lowercase.

  • Container names must be from 3 through 63 characters long.

Regarding getting 400 error with storage emulator, please check the storage client library version. If it's 3.x, then you would need to install storage emulator 2.2.1 released in preview today. More information about this can be found here: http://blogs.msdn.com/b/windowsazurestorage/archive/2014/01/16/windows-azure-storage-emulator-2-2-1-preview-release-with-support-for-2013-08-15-version.aspx

3
votes

This drove me insane for two days. Installing/Uninstalling the SDK, emulators, Azure Storage NuGet packages etc. I finally got the emulator working as well as real storage. The MSI you download to install the preview version of the emulator 2.2.1 contains a readme - I didnt know it was there, but it contains some pretty important instructions!

3. Copy all files from the following path:

        For 32-bit OS: "%ProgramFiles%\Windows Azure Storage Emulator 2.2.1\devstore"
        For 64-bit OS: "%ProgramFiles(x86)%\Windows Azure Storage Emulator 2.2.1\devstore"

   to the following path:

        "%ProgramFiles%\Microsoft SDKs\Windows Azure\Emulator\devstore"

   If prompted, choose to replace the existing files with the new ones.

It turns out the MSI doesnt update the files actually used by the emulator at run time! You have to perform this task by hand. I feel sooo stupid for not seeing this basic instruction. Turns out RTFM was the answer!