指定的容器不存在

编程入门 行业动态 更新时间:2024-10-18 20:31:01
本文介绍了指定的容器不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我坚持这个错误指定的容器不存在。

让我解释一下,

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) { CloudBlockBlob blob = cloudBlobClientReferenceName.GetBlockBlobReference(blobContentName); return blob; }

和我的 StorageConnectionString 是

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

容器上传和存储帐户DUW'存在。

container 'upload' and the storage account 'duw' exist.

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

堆栈跟踪:

在Microsoft.WindowsAzure.StorageClient.Tasks.Task 1.get_Result()     在Microsoft.WindowsAzure.StorageClient.Tasks.Task 1.ExecuteAndWait()     在Microsoft.WindowsAzure.StorageClient.TaskImplHelper.ExecuteImpl(implement执行Func`1)     在Microsoft.WindowsAzure.StorageClient.CloudBlob.UploadFromStream(流源,BlobRequestOptions选项)     在Microsoft.WindowsAzure.StorageClient.CloudBlob.UploadFromStream(流源)     在DAL.Handlers.BlobHandler.CreateAd(HttpPostedFileBase文件,广告模特)在D:\\ DU服务器\\干线\\杜服务器\\ DAL \\处理程序\\ BlobHandler.cs:行151

at Microsoft.WindowsAzure.StorageClient.Tasks.Task1.get_Result() at Microsoft.WindowsAzure.StorageClient.Tasks.Task1.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)未找到}

任何机构可以帮助我理清了这一点。

can any body help me to sort this out.

推荐答案

短版

请尝试以下code为 BlobPropertySetting 功能:

Try the following code for BlobPropertySetting function:

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

现在的更长的版本:)

你得到这个错误的原因是因为你在构建 BlobPropertySetting 的 CloudBlockBlob 对象的方式方法。当您使用code,它创建具有下列URI的blob对象: duv.blob.core.windows/blobContentName 。如果您发现,没有容器名称存在。因为没有容器名称,存储客户端库假设你想创建 $根一滴的blob容器,它是一种特殊的blob容器。你可以阅读更多关于它在这里:msdn.microsoft/en-us/library/windowsazure/hh488356.aspx.由于您的存储帐户没有这个容器,你得到 404 - 未找到资源错误

The reason you're getting this error is because of the way you are constructing the CloudBlockBlob object in BlobPropertySetting method. When you use your code, it creates a blob object with the following URI: duv.blob.core.windows/blobContentName. If you notice, there's no container name there. Since there's no container name, storage client library assumes that you're trying to create a blob in $root blob container which is a special blob container. You can read more about it here: msdn.microsoft/en-us/library/windowsazure/hh488356.aspx. Since your storage account does not have this container, you get 404 - Resource Not Found error.

更多推荐

指定的容器不存在

本文发布于:2023-11-15 22:34:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1598554.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不存在   容器

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!