سؤال

The following code throws an error on the "CreateIfNotExist" method call. I am attempting to connect to my Azure Blob storage and create a new container called "images"

var storageAccount = new CloudStorageAccount(
    new StorageCredentialsAccountAndKey("my_account_name", "my shared key"),
    "https://blob.core.windows.net/",
    "https://queue.core.windows.net/",
    "https://table.core.windows.net/"
);
var blobClient = storageAccount.CreateCloudBlobClient();
var blobContainer = blobClient.GetContainerReference("images");
blobContainer.CreateIfNotExist();

The error is:

[StorageClientException: The requested URI does not represent any resource on the server.]

The "images" container does not exist but I was expecting it to be created instead of an error to be thrown. What am I doing wrong?

I have tried HTTP instead of HTTPS but the result is the same error.

هل كانت مفيدة؟

المحلول

I have figured out that I must use a different syntax

var storageAccount = new CloudStorageAccount(
   new StorageCredentialsAccountAndKey("my_account_name", "my shared key"));
var blobClient = storageAccount.CreateCloudBlobClient(); 
var blobContainer = blobClient.GetContainerReference("images"); 
blobContainer.CreateIfNotExists(); 

Notice how the end points are omited. Evidently, the CloudBlobClient can figure out the appropriate URIs automatically.

نصائح أخرى

Are you sure the account name and shared key are correct? You might try installing Fiddler to take a look at the HTTP traffic to make sure nothing there looks suspicious.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top