指定的容器不存在 [英] The specified container does not exist

查看:1298
本文介绍了指定的容器不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

让我解释一下,

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对象: https://duv.blob.core.windows.net/blobContentName 。如果您发现,没有容器名称存在。因为没有容器名称,存储客户端库假设你想创建 $根一滴的blob容器,它是一种特殊的blob容器。你可以阅读更多关于它在这里:<一href=\"http://msdn.microsoft.com/en-us/library/windowsazure/hh488356.aspx\">http://msdn.microsoft.com/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: https://duv.blob.core.windows.net/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: http://msdn.microsoft.com/en-us/library/windowsazure/hh488356.aspx. Since your storage account does not have this container, you get 404 - Resource Not Found error.

这篇关于指定的容器不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆