Skip to content

Azure Blob UploadFile Fail

January 27, 2011

I tried uploading a large file from my local machine to an Azure blob store, using the following code:

void UploadFile(string path, string accountConnectionString)
    CloudStorageAccount account = CloudStorageAccount.Parse(accountConnectionString);
    CloudBlobClient blobClient = account.CreateCloudBlobClient();
    CloudBlobContainer container = blobClient.GetContainerReference("mycontainer");
    CloudBlob blob = container.GetBlobReference(Path.GetFileName(path));

Simple enough, and it worked fine on small files, so imagine my surprise when it consistently threw the exception “The specified blob already exists” on attempts to upload a large file.

Fortunately, the problem turned out to be simple enough to fix (with the help of some forum searches). Add the line following the creation of the blob client and the problem goes away:

    CloudBlobClient blobClient = account.CreateCloudBlobClient();
    blobClient.ParallelOperationThreadCount = 1;

The initial setting for parallel thread count was 2. And when uploading a large file (apparently 4MB is the crossover, which is the Azure blob “block” size), the parallel threads get confused over who is creating the file.

I mention it here to save others from hapless attempts at finding this kind of information on MSDN (like god forbid, on the UploadFile() documentation page).

No comments yet

Leave a Reply

Your email address will not be published. Required fields are marked *