我有这段代码:
CloudBlob blob = _container.GetBlobReference(relativefilePath);
blob.Properties.ContentType = contentType;
blob.UploadFromStream(fileContent);
当我将大文件(150Mb)上传到开发存储时,我遇到了这个例外:
Microsoft.WindowsAzure.StorageClient.StorageClientException 用户代码未处理 消息=指定的blob已存在。
源= Microsoft.WindowsAzure.StorageClient
但事实并非如此,该文件不存在。实际上,我不知道为什么这应该是一个问题,每次我尝试,我都可以覆盖现有的blob w / o任何问题。最令人惊奇的是,当VS中出现异常时,我选择“启用编辑”,我将执行光标(黄色箭头)移动到显示的第二行代码,执行...然后IT WORKS !!
我只使用大文件获取异常,我不明白为什么。
这是一个例外细节:
Microsoft.WindowsAzure.StorageClient.StorageClientException was unhandled by user code
Message=The specified blob already exists.
Source=Microsoft.WindowsAzure.StorageClient
StackTrace:
at Microsoft.WindowsAzure.StorageClient.Tasks.Task`1.get_Result()
at Microsoft.WindowsAzure.StorageClient.Tasks.Task`1.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 AzureBlobOperations.AzureFileContainerOperations.PutFile(String relativefilePath, Stream fileContent, String contentType, Boolean createIfNotExists) in C:\Users\valeriano.tortola\Documents\Visual Studio 2010\Projects\TestWithBlobs\AzureBlobOperations\AzureFileOperations.cs:line 61
at TestWithBlobs.Web.Controllers.HomeController.PostFile(HttpPostedFileBase fileUpload) in C:\Users\valeriano.tortola\Documents\Visual Studio 2010\Projects\TestWithBlobs\TestWithBlobs.Web\Controllers\HomeController.cs:line 31
at lambda_method(Closure , ControllerBase , Object[] )
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__DisplayClassd.<InvokeActionMethodWithFilters>b__a()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
InnerException: System.Net.WebException
Message=The remote server returned an error: (409) Conflict.
Source=System
StackTrace:
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at Microsoft.WindowsAzure.StorageClient.EventHelper.ProcessWebResponse(WebRequest req, IAsyncResult asyncResult, EventHandler`1 handler, Object sender)
InnerException:
答案 0 :(得分:10)
这是开发存储的已知问题。当启动多个线程来上传块(构成blob)时会发生这种情况。基本上发生的事情是开发存储使用SQL Server作为数据存储。现在它做的第一件事就是进入存储blob信息的表。如果有多个线程正在运行,那么所有这些线程都将尝试执行相同的操作。第一个线程成功后,后续线程将导致引发此异常。