gpt4 book ai didi

c# - 指定的容器不存在

转载 作者:太空狗 更新时间:2023-10-29 20:17:12 24 4
gpt4 key购买 nike

遇到此错误指定的容器不存在。

让我解释一下,

CloudBlobClient blobStorage = GetBlobStorage("upload");
CloudBlockBlob blob = BlobPropertySetting(blobStorage, Guid.NewGuid().ToString().ToLower() + Path.GetExtension(file.FileName));
blob.UploadFromStream(file.InputStream);

public static CloudBlobClient GetBlobStorage(string cloudBlobContainserName)
{
CloudBlobClient blobStorage;

try
{
var storageAccount = CloudStorageAccount.FromConfigurationSetting("StorageConnectionString");
blobStorage = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobStorage.GetContainerReference(cloudBlobContainserName);

container.CreateIfNotExist();

var permissions = container.GetPermissions();
permissions.PublicAccess = BlobContainerPublicAccessType.Container;

container.SetPermissions(permissions);
}
catch (Exception ex)
{
Logger.LogError(Log4NetLogger.Category.Exception, "Error in : BlobHandler.GetBlobStorage :>> Exception message: " + ex.Message);
throw;
}

return blobStorage;
}

public static CloudBlockBlob BlobPropertySetting(CloudBlobClient cloudBlobClientReferenceName, string blobContentName)
{
return cloudBlobClientReferenceName.GetBlockBlobReference(blobContentName);
}

我的StorageConnectionString

<Setting name="StorageConnectionString" value="DefaultEndpointsProtocol=https;AccountName=duw;AccountKey=bla bla" />

容器“upload”和存储帐户“duw”存在。

执行blob.UploadFromStream(file.InputStream);语句会导致错误。

堆栈跟踪:

at Microsoft.WindowsAzure.StorageClient.Tasks.Task`1.get_Result()at Microsoft.WindowsAzure.StorageClient.Tasks.Task`1.ExecuteAndWait()at Microsoft.WindowsAzure.StorageClient.TaskImplHelper.ExecuteImpl(Func`1 impl)at Microsoft.WindowsAzure.StorageClient.CloudBlob.UploadFromStream(Stream source, BlobRequestOptions options)at Microsoft.WindowsAzure.StorageClient.CloudBlob.UploadFromStream(Stream source)at DAL.Handlers.BlobHandler.CreateAd(HttpPostedFileBase file, Advertisement model) in D:\DU Server\trunk\Du Server\DAL\Handlers\BlobHandler.cs:line 151

内部异常:

{“远程服务器返回错误:(404) 未找到。”}

任何人都可以帮我解决这个问题吗?

最佳答案

简短版本

尝试使用以下代码来实现 BlobPropertySetting 函数:

 public static CloudBlockBlob BlobPropertySetting(CloudBlobClient cloudBlobClientReferenceName, string blobContentName)
{
CloudBlockBlob blob = cloudBlobClientReferenceName.GetBlockBlobReference("upload/" + blobContentName);
return blob;
}

现在是更长的版本:)

您收到此错误的原因是您在 BlobPropertySetting 方法中构造 CloudBlockBlob 对象的方式所致。当您使用代码时,它会创建一个具有以下 URI 的 blob 对象:https://duv.blob.core.windows.net/blobContentName。如果您注意到,那里没有容器名称。由于没有容器名称,存储客户端库假定您尝试在 $root Blob 容器中创建 Blob,这是一个特殊的 Blob 容器。您可以在这里阅读更多相关信息:http://msdn.microsoft.com/en-us/library/windowsazure/hh488356.aspx 。由于您的存储帐户没有此容器,因此您会收到 404 - Resource Not Found 错误。

关于c# - 指定的容器不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18864002/

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