【问题标题】:The specified blob does not exist --even when the bob does exists指定的 blob 不存在——即使 bob 确实存在
【发布时间】:2013-10-13 14:51:42
【问题描述】:

使用下面的代码,我收到一条错误消息:

指定的 blob 不存在

当我调试我的代码时,.CreateBlobContainer - 我可以看到创建了指定的 bob,然后在我的代码之外我手动复制并粘贴了一个文本文件到我的 blob。然后当我到达代码的最后一行,.DownloadToStream ,它会抛出异常错误,说指定的 blob 不存在。 --即使鲍勃确实存在

下面的示例代码有什么问题:

        string testContainerName = "xyz"+Common.GenerateRandomEightCharString().ToLower();

        var testBlobClient = BlobClientFactory.CreateBlobClient(true);
        var testContainer = BlobClientFactory.CreateBlobContainer(testBlobClient, testContainerName);
        var zipOutputStream = new ZipOutputStream(Response.OutputStream)
        {
            CompressionLevel = CompressionLevel.Default
        };
        zipOutputStream.CompressionLevel = CompressionLevel.Default;
        zipOutputStream.EnableZip64 = Zip64Option.AsNecessary;
        CloudBlob testBlob = testBlobClient.GetBlobReference(testBlobClient.BaseUri.ToString() + testContainerName);
        zipOutputStream.PutNextEntry(testContainerName);
        BlobRequestOptions options = new BlobRequestOptions();
        options.Timeout = TimeSpan.FromSeconds(20.0);
        testBlob.DownloadToStream(zipOutputStream, options); //Exception error here

这是异常消息。

Microsoft.WindowsAzure.StorageClient.StorageClientException was unhandled by user code
  HResult=-2146233088
  Message=The specified blob does not exist.
  Source=Microsoft.WindowsAzure.StorageClient
  StackTrace:
       at Microsoft.WindowsAzure.StorageClient.Tasks.Task`1.get_Result()
       at Microsoft.WindowsAzure.StorageClient.Tasks.Task`1.Execute()
       at Microsoft.WindowsAzure.StorageClient.RequestWithRetry.RequestWithRetrySyncImpl[TResult](ShouldRetry retryOracle, SynchronousTask`1 syncTask)
       at Microsoft.WindowsAzure.StorageClient.TaskImplHelper.ExecuteSyncTaskWithRetry[TResult](SynchronousTask`1 syncTask, RetryPolicy policy)
       at Microsoft.WindowsAzure.StorageClient.CloudBlob.DownloadToStream(Stream target, BlobRequestOptions options)
       at ............................
       at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
       at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
       at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
  InnerException: System.Net.WebException
       HResult=-2146233079
       Message=The remote server returned an error: (404) Not Found.
       Source=System
       StackTrace:
            at System.Net.HttpWebRequest.GetResponse()
            at Microsoft.WindowsAzure.StorageClient.EventHelper.ProcessWebResponseSync(WebRequest req, EventHandler`1 handler, Object sender)
       InnerException: 

【问题讨论】:

  • 我没有看到上传 Blob 的代码。您在哪里上传代码中的 blob?
  • 当我在.CreateBlobContainer 调试我的代码时 - 我可以看到创建了指定的bob,然后在我的代码之外我手动复制并粘贴了一个文本文件到我的blob中。然后当我到达代码的最后一行,.DownloadToStream,它抛出异常错误说指定的blob不存在

标签: c# azure azure-storage azure-blob-storage azure-table-storage


【解决方案1】:

我刚刚重新启动了我的 webrole,它开始工作了

【讨论】:

    【解决方案2】:

    根据您的评论,我知道发生了什么。基本上,您正在通过代码创建一个 blob 容器(将其视为一个文件夹),然后手动复制该容器中的文件。但是,您用于 blob 的 URL(将其视为文件)是容器的 URL,而不是文件的 URL。

    您需要做的是将文件名附加到 blob URL。因此,假设您在容器中手动复制的文件名为 xyz.txt,您将使用以下代码创建 testBlob 对象:

    CloudBlob testBlob = testBlobClient.GetBlobReference(testBlobClient.BaseUri.ToString() + testContainerName + "/xyz.txt");
    

    试一试。它应该可以工作。

    【讨论】:

    • 您能否通过 Fiddler 之类的工具跟踪您的请求,并查看您在调用 DownloadToStream 方法时访问的是哪个 URL?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-21
    • 2021-06-10
    • 1970-01-01
    • 2019-05-02
    • 2012-06-30
    • 2013-12-14
    • 2019-04-03
    相关资源
    最近更新 更多