Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure storage error: "The specified blob already exists", but it doesn't!

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\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: 
like image 224
vtortola Avatar asked Feb 04 '11 12:02

vtortola


People also ask

What is BlobContainerClient?

Microsoft makes no warranties, express or implied, with respect to the information provided here. The BlobContainerClient allows you to manipulate Azure Storage containers and their blobs.

Is Azure Blob storage region specific?

Blob storage can certainly be shared between users in different regions. Blob storage resources are accessible over HTTP protocol so it doesn't really matter where your users are.


1 Answers

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.

like image 169
Gaurav Mantri Avatar answered Sep 27 '22 01:09

Gaurav Mantri