Cloud Zone is brought to you in partnership with:

An all-round technology-curious software developer who can mostly be found plugging away with C# and SQL Server development, with the odd bit of NOSQL thrown in for good measure. Always looking to sponge up knowledge on a wide range of technologies. Adrian is a DZone MVB and is not an employee of DZone and has posted 6 posts at DZone. You can read more from them at their website. View Full User Profile

A Vague Error While Creating Azure Blob Storage Container

05.24.2012
| 2009 views |
  • submit to reddit
I received a rather...vague...error when trying out a bit of .NET code to connect to a Windows Azure Blob Storage account, and create a new container in which to store some blobs.

The code

CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
    "DefaultEndpointsProtocol=https;AccountName=REMOVED;AccountKey=REMOVED");

CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
            
CloudBlobContainer container = 
    blobClient.GetContainerReference("TestContainer1");

container.CreateIfNotExist(); // This error'd

The error

A StorageClientException was thrown saying "One of the request inputs is out of range.". An inner WebException showed that "The remote server returned an error: (400) Bad Request."

The cause

I'd assumed (incorrectly) that a container name could be pretty much any string. But that's not the case. As per this MSDN reference, a container name must:
  • be in lowercase (this was the cause in my case)
  • start with a letter or a number and only contain letters, numbers and hyphens (multiple consecutive hyphens are not allowed)
  • be between 3 and 63 characters long
The "Naming and Referencing Containers, Blobs and Metadata" reference is worth a bookmark.
Published at DZone with permission of Adrian Hills, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)