我正在使用Azure开发Blob存储..
上传blob效果很好,我可以双击visual studio blob容器视图中上传的图像并打开图片......
但如果你看一下这张照片:
...... Uri有问题吗?
以下是我正在使用的代码:
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;
以下是我如何存储blob:
public CloudBlockBlob UploadBlob(Stream fileStream, string fileName)
{
var blobName = Guid.NewGuid() + fileName;
var blockBlob = GetContainer().GetBlockBlobReference(blobName);
blockBlob.UploadFromStream(fileStream);
return blockBlob;
}
以下是我如何获得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;
}
这是blob中blob的样子。存储(可点击并可从那里查看)
Name : bla-bla-bla.jpg
Content Type : application/octet-stream
URL : http://127.0.0.1:10000/devstoreaccount1/userid1/bla-bla-bla.jpg
那么......我应该如何改变我获得正常网址的方式?
Soo ..有没有明显的事我在这里做错了?
这是完整的NET响应消息:
{"$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)"}}
答案 0 :(得分:12)
您似乎在应用程序的BlobUrl
属性中存储了blob的绝对URL。根据{{3}}的文档,它应该是 name of the blob
。所以在你的情况下,它应该只是图像文件的名称。
如果仔细查看您共享的屏幕截图,特别是blob的URI属性,您会发现问题所在。 Blob的Uri属性为http://127.0.0.1:10000/devstoreaccount1/userid1/http://127.0.0.1:10000/devstoreaccount1/userid1/85066...mongo.jpg
,而不是http://127.0.0.1:10000/devstoreaccount1/userid1/85066...mongo.jpg
。