Azure CloudBlockBlob. Unable to find blob when DownloadToStream. Does Uri seem to be repeated?

I am using Azure Development Blob Storage.

Downloading blob works fine, and I can double-click the image loaded into the visual view of the blob container's container and open the image ...

But if you look at this image:

enter image description here

... is something wrong with Uri?

Here is the code I'm using:

public MemoryStream DownloadBlob(int id) { Photo photo = PhotoServices.GetPhotoById(id); var cloudBlobContainer = _blobClient.GetContainerReference(CurrentBlobContainerName); var blob = cloudBlobContainer.GetBlockBlobReference(photo.BlobUrl); var memorystream = new MemoryStream(); // THIS LINE GIVES BLOB NOT FOUND EXCEPTION blob.DownloadToStream(memorystream); memorystream.Position = 0; return memorystream; 

This is how I store blobs:

 public CloudBlockBlob UploadBlob(Stream fileStream, string fileName) { var blobName = Guid.NewGuid() + fileName; var blockBlob = GetContainer().GetBlockBlobReference(blobName); blockBlob.UploadFromStream(fileStream); return blockBlob; } 

This is how I get blob:

 public MemoryStream DownloadBlob(int id) { Photo photo = PhotoServices.GetPhotoById(id); var cloudBlobContainer = _blobClient.GetContainerReference(CurrentBlobContainerName); var blob = cloudBlobContainer.GetBlockBlobReference(photo.BlobUrl); var memorystream = new MemoryStream(); memorystream.Position = 0; blob.DownloadToStream(memorystream); return memorystream; } 

This is what blob looks like in dev. storage (available for viewing and viewing)

  Name : bla-bla-bla.jpg Content Type : application/octet-stream URL : http://127.0.0.1:10000/devstoreaccount1/userid1/bla-bla-bla.jpg 

So ... what should I change to get a picture to get a normal URL?

Su ... are there obvious things I'm doing wrong here?

here is the complete net response msg request:

 {"$id":"1","Message":"An error has occurred.","ExceptionMessage":"The remote server returned an error: (404) Not Found.","ExceptionType":"Microsoft.WindowsAzure.Storage.StorageException","StackTrace":" at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext)\r\n at Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.DownloadRangeToStream(Stream target, Nullable`1 offset, Nullable`1 length, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext)\r\n at Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.DownloadToStream(Stream target, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext)\r\n at ServiceLibrary.Services.StorageServices.DownloadBlob(Int32 id) in c:\\PhotoApp\\ServiceLibrary\\Services\\StorageServices.cs:line 116\r\n at PhotoWebApp.Controllers.PhotoSubmitController.GetPhotoById(Int32 id) in c:\\PhotoApp\\PhotoWebApp\\Controllers\\PhotoSubmitController.cs:line 28\r\n at lambda_method(Closure , Object , Object[] )\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()","InnerException":{"$id":"2","Message":"An error has occurred.","ExceptionMessage":"The remote server returned an error: (404) Not Found.","ExceptionType":"System.Net.WebException","StackTrace":" at System.Net.HttpWebRequest.GetResponse()\r\n at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext)"}} 
+6
source share
1 answer

It seems that you are saving the absolute blob BlobUrl in the BlobUrl property in your application. Based on the documentation for CloudBlobContainer.GetBlockBlobReference it should be name of the blob . Therefore, in your case, it should be just the name of the image file.

If you carefully look at the screenshot that you shared, in particular the blob URI property, you will notice a problem. Blob Uri property http://127.0.0.1:10000/devstoreaccount1/userid1/http://127.0.0.1:10000/devstoreaccount1/userid1/85066...mongo.jpg instead of http://127.0.0.1:10000/devstoreaccount1/userid1/85066...mongo.jpg .

+12
source

Source: https://habr.com/ru/post/972926/


All Articles