gpt4 book ai didi

asp.net-mvc - 创建动态 blob 容器名称

转载 作者:行者123 更新时间:2023-12-02 06:34:37 25 4
gpt4 key购买 nike

我正在尝试创建一个 blob 容器,其名称基于作为参数传递到函数中的值 (AssetID)。

    public CloudBlobContainer GetCloudBlobContainer(int id)
{

// Retrieve storage account from connection-string
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["StorageConnection"].ConnectionString);

// Create the blob client
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

// Retrieve a reference to a container
CloudBlobContainer blobContainer = blobClient.GetContainerReference("AssetDocs" + id);

try
{

// Create the container if it doesn't already exist
if (blobContainer.CreateIfNotExist())
{

blobContainer.SetPermissions(
new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob }
);
}
}
catch (WebException e)
{
return blobContainer;
}

return blobContainer;
}

当我运行代码时,出现以下异常:

An exception of type 'Microsoft.WindowsAzure.StorageClient.StorageClientException' occurred in Microsoft.WindowsAzure.StorageClient.dll but was not handled in user code

Additional information: One of the request inputs is out of range.

我尝试添加一个 try...catch 但这似乎并没有捕获异常,因此我可以找到更多详细信息。

如果尝试添加 id.ToString() 并完全删除 id,但这也不起作用。

我做错了什么?

最佳答案

破解了!容器名称必须小写。

 // Retrieve a reference to a container 
CloudBlobContainer blobContainer = blobClient.GetContainerReference("assetdocs" + id);

关于asp.net-mvc - 创建动态 blob 容器名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26370920/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com