문제

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