08 October 2012 Azure, Blob, Fix Robert Muehsig

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:

  1. Container names must start with a letter or number, and can contain only letters, numbers, and the dash (-) character.
  2. Every dash (-) character must be immediately preceded and followed by a letter or number; consecutive dashes are not permitted in container names.
  3. All letters in a container name must be lowercase.
  4. Container names must be from 3 through 63 characters long.
  5. </ol>

     

    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.


Written by Robert Muehsig

Software Developer - from Dresden, Germany, now living & working in Switzerland. Microsoft MVP & Web Geek.
Other Projects: KnowYourStack.com | ExpensiveMeeting | EinKofferVollerReisen.de

If you like the content and want to support me you could buy me a beer or a coffee via Litecoin or Bitcoin - thanks for reading!