0
votes

With my code below, I am getting an error message:

The specified blob does not exist

when I debug my code ,at .CreateBlobContainer -I can see the specified bob got created ,Then outside the my code I manually copied and pasted a text file into my blob.Then when I reach the last line of the code ,.DownloadToStream ,it throws exception error saying the specified blob doesnot exist. --even when the bob does exists

What's wrong with my sample code below:

        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

Here is the exception message .

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: 
2
I didn't see the code to upload the blob. Where are you uploading the blob in your code?Gaurav Mantri
when I debug my code ,at .CreateBlobContainer -I can see the specified bob got created ,Then outside the my code I manually copied and pasted a text file into my blob.Then when I reach the last line of the code ,.DownloadToStream ,it throws exception error saying the specified blob doesnot existLee

2 Answers

1
votes

I just restarted my webrole and it started working

0
votes

Based on your comment, I see what's happening. Basically you are creating a blob container (think of it as a folder) through the code and then manually copying a file in that container. However the URL you're using for the blob (think of it as a file) is that of the container instead of the file.

What you need to do is append the name of the file to the blob URL. So assuming, the file you manually copied in the container is named xyz.txt, you would create your testBlob object using the code would be:

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

Give it a try. It should work.