12

我被这个错误困住了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的是

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

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

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

堆栈跟踪 :

在 Microsoft.WindowsAzure.StorageClient.Tasks.Task 1.get_Result() at Microsoft.WindowsAzure.StorageClient.Tasks.Task1.ExecuteAndWait() 在 Microsoft.WindowsAzure.StorageClient.TaskImplHelper.ExecuteImpl(Func`1 impl) 在 Microsoft.WindowsAzure.StorageClient.CloudBlob.UploadFromStream(Stream source, BlobRequestOptions options) 在 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

内部异常:

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

任何机构都可以帮我解决这个问题。

4

2 回答 2

8

精简版

试试下面的BlobPropertySetting函数代码:

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

现在是更长的版本:)

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

于 2013-09-18T05:44:06.463 回答
4

我很晚了,但仍然想我的回答是否对任何人有用。

我通过输入正确的“容器名称”解决了这个错误。默认情况下是不同的。我已经克隆了这个 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')
;
于 2018-10-26T09:16:33.257 回答