I have this code:
CloudBlob blob = _container.GetBlobReference(relativefilePath);
blob.Properties.ContentType = contentType;
blob.UploadFromStream(fileContent);
When I upload a large file (150Mb) to the development storage and I got this exception:
Microsoft.WindowsAzure.StorageClient.StorageClientException was unhandled by user code
Message=The specified blob already exists. Source=Microsoft.WindowsAzure.StorageClient
But it's not true, the file doesn't exist. Actually, I don't know why that should be a problem, every time I've tried, I can overwrite an existing blob w/o any problem. The most amazing is that when the exception appears in VS, I select "Enable editing", I move the execution cursor (the yellow arrow) to the 2nd line of code showed, execute... and then IT WORKS!!
I get the exception only with large files, and I don't understand why.
This is the exception detail:
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\valer开发者_JAVA技巧iano.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:
This is a known issue with development storage. This happens when there are multiple threads launched to upload the blocks (which constitute the blob). Basically what is happening is that development storage makes use of SQL Server as the data store. Now first thing it does is makes an entry into the table which stores blob information. If there are multiple threads working then all of these threads will try to perform the same operation. After the first thread succeeds, the subsequent threads will result in this exception being raised.
精彩评论