Quantcast
Channel: Code Inside Blog
Viewing all articles
Browse latest Browse all 358

“Http 400 Bad Request” beim Speichern in den Azure Blob Storage?

$
0
0
image.png

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.

 

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.


Viewing all articles
Browse latest Browse all 358

Trending Articles