简体   繁体   中英

Can't create blob container on Azure Blob Storage

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM