If you receive the exception “the remote server returned an error: (400) Bad Request” while creating a Blob container with Azure you are most likely violate the name conventions:
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.
Small error but it still has the potential to make me confused
There is already a good guide about how to deal with the BlobStorage here with nice example code. For example how to upload a file into the Blob storage:
// Retrieve storage account from connection string CloudStorageAccount storageAccount = CloudStorageAccount.Parse( CloudConfigurationManager.GetSetting("StorageConnectionString")); // Create the blob client CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); // Retrieve reference to a previously created container CloudBlobContainer container = blobClient.GetContainerReference("mycontainer"); // Retrieve reference to a blob named "myblob" CloudBlob blob = container.GetBlobReference("myblob"); // Create the container if it doesn't already exist container.CreateIfNotExist(); // Create or overwrite the "myblob" blob with contents from a local file using (var fileStream = System.IO.File.OpenRead(@"path\myfile")) { blob.UploadFromStream(fileStream); }
The exception will appear on the line “container.CreatelNotExist()” if you wrote the container name in capital letters. Of course the hint was from Stackoverflow.