无法在Azure Blob存储上创建Blob容器
-
05-10-2019 - |
题
以下代码在“ createifnotexist”方法调用上引发错误。我正在尝试连接到我的Azure Blob存储,并创建一个名为“图像”的新容器
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();
错误是:
[StorageClientException: The requested URI does not represent any resource on the server.]
“图像”容器不存在,但我期望将其创建,而不是抛出错误。我究竟做错了什么?
我尝试过HTTP而不是HTTP,但结果是相同的错误。
解决方案
我已经发现我必须使用其他语法
var storageAccount = new CloudStorageAccount(
new StorageCredentialsAccountAndKey("my_account_name", "my shared key"));
var blobClient = storageAccount.CreateCloudBlobClient();
var blobContainer = blobClient.GetContainerReference("images");
blobContainer.CreateIfNotExists();
注意如何省略终点。显然,CloudBlobClient可以自动找出适当的URI。
其他提示
您确定帐户名和共享密钥是否正确?您可以尝试安装提琴手来查看HTTP流量,以确保那里没有任何可疑。
不隶属于 StackOverflow