指定的容器不存在

我遇到了这个错误The specified container does not exist.

让我解释,

 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

   

容器’上传’和存储帐户’duw’存在。

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

堆栈跟踪 :

在Microsoft.WindowsAzure的Microsoft.WindowsAzure.StorageClient.Tasks.Task 1.get_Result() at Microsoft.WindowsAzure.StorageClient.Tasks.Task 1.ExecuteAndWait()在Microsoft.WindowsAzure的Microsoft.WindowsAzure.StorageClient.TaskImplHelper.ExecuteImpl(Func`1 impl)位于D:\ DU服务器\ trunk中DAL.Handlers.BlobHandler.CreateAd(HttpPostedFileBase文件,广告模型)的Microsoft.WindowsAzure.StorageClient.CloudBlob.UploadFromStream(流源)的.StorageClient.CloudBlob.UploadFromStream(流源,BlobRequestOptions选项) \ Du Server \ DAL \ Handlers \ BlobHandler.cs:第151行

内在exception:

{"The remote server returned an error: (404) Not Found."}

任何人都可以帮助我解决这个问题。

精简版

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/blobContentNamehttps://duv.blob.core.windows.net/blobContentName 。 如果你注意到,那里没有容器名称。 由于没有容器名称,因此存储客户端库假定您尝试在$root blob容器中创建一个blob,这是一个特殊的blob容器。 您可以在此处阅读更多相关信息: http : //msdn.microsoft.com/en-us/library/windowsazure/hh488356.aspx 。 由于您的存储帐户没有此容器,因此您将收到404 - Resource Not Found错误。

我很晚,但仍然认为我的答案对任何人都有用。

我通过输入正确的“容器名称”解决了这个错误。 默认情况下它是不同的。 我克隆了这个GIT项目: https : //github.com/Azure-Samples/storage-blob-upload-from-webapp-node

 const express = require('express') , router = express.Router() , azureStorage = require('azure-storage') , blobService = azureStorage.createBlobService() , containerName = 'container' // added container name here, as my container name , config = require('../config') ;