问题描述
我有一个要求,即在创建公司时会在我的storageaccount中创建一个关联的blob存储容器,并将容器名称设置为传入的字符串变量.我尝试了以下操作:
I have a requirement whereby on creation of a company an associated blob storage container is created in my storageaccount with the container name set to the string variable passed in. I have tried the following:
public void AddCompanyStorage(string subDomain)
{
//get the storage account.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
System.Configuration.ConfigurationManager.AppSettings["StorageConnectionString"].ToString());
//blob client now
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
//the container for this is companystyles
CloudBlobContainer container = new CloudBlobContainer("https://mystore.blob.core.windows.net/" + subDomain);
}
但是,这并没有创建容器,我是否以错误的方式进行操作?这可能吗?
This however has not created the container as I expected, am I going about this in the wrong manner? Is this possible?
推荐答案
public void AddCompanyStorage(string subDomain)
{
//get the storage account.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
System.Configuration.ConfigurationManager.AppSettings["StorageConnectionString"].ToString());
//blob client now
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
//the container for this is companystyles
CloudBlobContainer container = blobClient.GetContainerReference(subDomain);
//Create a new container, if it does not exist
container.CreateIfNotExists();
}
遵循容器名称指南:
- 容器名称必须是有效的DNS名称,符合
遵循以下命名规则:容器名称必须以字母或
开头数字,并且只能包含字母,数字和破折号(-)
字符. -
每个破折号(-)字符必须紧随其后字母或数字;容器中不允许连续的破折号名称.
- A container name must be a valid DNS name, conforming to the
following naming rules: Container names must start with a letter or
number, and can contain only letters, numbers, and the dash (-)
character. Every dash (-) character must be immediately preceded and followed bya letter or number; consecutive dashes are not permitted in containernames.
容器名称中的所有字母都必须小写.
All letters in a container name must be lowercase.
容器名称的长度必须在3到63个字符之间.
Container names must be from 3 through 63 characters long.
这篇关于以编程方式创建Blob存储容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!