
Wer eine Exception “The remote server returned an error: (400) Bad Request.” beim Erstellen eines Blob Containers auf Azure bekommt, der wird höchst wahrscheinlich die Namenskonvention verletzen:
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.
Kleiner Fehler, welcher einen doch leicht verunsichern kann
Einen sehr guten Guide zum Umgang mit dem BlobStorage findet man zudem hier mit gutem Beispielcode. Hier z.B. wie man eine Datei in den Blob Storage hochlädt:
// 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); }
Die obrige Exception würde bei der Zeile “container.CreateIfNotExist()” auftreten, wenn der Containername groß geschrieben wäre. Natürlich kam der entsprechende Tipp von Stackoverflow.