Vivek Misra
Vivek Misra

Reputation: 265

StorageClientException On Blob.UploadAsync methods

I have implemented following async blob upload method to upload multiple blocks.

        var container = GetContainer(containerName);

        var blob = container.GetBlockBlobReference(blobName);

        String[] base64EncodedBlockIds = new String[10];// 10- number of Blocks

        //To upload the blocks in parallel - 10 parallel blocks
        ParallelLoopResult parallelLoopResult = Parallel.For(0,10, i =>
            {
                String base64EncodedBlockId = Convert.ToBase64String(System.BitConverter.GetBytes(i));                                 
                byte[] bytesMemoryStream = GetBytesFromStream(stream);
                using (MemoryStream memoryStream = new MemoryStream(bytesMemoryStream))
                {
                    blob.PutBlock(base64EncodedBlockId, memoryStream, null);// throws an exception "The value for one of the HTTP headers is not in the correct format"

                }
                base64EncodedBlockIds[i] = base64EncodedBlockId;
            });
        blob.PutBlockList(base64EncodedBlockIds); 

It throws an exception "The value for one of the HTTP headers is not in the correct format".

Need your inputs

Regards, Vivek

Upvotes: 1

Views: 374

Answers (2)

escargot agile
escargot agile

Reputation: 22379

In my case "The value for one of the HTTP headers is not in the correct format" error occurred because I was trying to write an empty block (memoryStream had 0 bytes). PutBlock failed beause the content length was 0 in the header.

Upvotes: 2

Brian Reischl
Brian Reischl

Reputation: 7356

BlockIDs within a blob must all be the same length (number of characters). BlockID "10" is longer than the others, which is probably the source of your problem.

One solution would be to zero-pad the BlockIDs to the same length.

Upvotes: 2

Related Questions