Record on Azure Block Blobs

I use PutBlock and PutBlockList to load data into a block block, the code that I use for this is given below: -

CloudBlobContainer container = blobStorage.GetContainerReference("devicebackups");
var permissions = container.GetPermissions();
permissions.PublicAccess = BlobContainerPublicAccessType.Container;
container.SetPermissions(permissions);
CloudBlockBlob blob = container.GetBlockBlobReference(serialNo.ToLower() + " " + dicMonths[DateTime.Now.Month]);
try
{
    var serializer = new XmlSerializer(typeof(List<EnergyData>));
    var stringBuilder = new StringBuilder();
    using (XmlWriter writer = XmlWriter.Create(stringBuilder))
    {
        try
        {
            serializer.Serialize(writer, deviceData);
            byte[] byteArray = Encoding.UTF8.GetBytes(stringBuilder.ToString());

            List<string> blockIds = new List<string>();
            try 
            { 
                blockIds.AddRange(blob.DownloadBlockList(BlockListingFilter.Committed).Select(b => b.Name)); 
            }
            catch (StorageClientException e)
            {
                if (e.ErrorCode != StorageErrorCode.BlobNotFound)
                {
                    throw;
                }
                blob.Container.CreateIfNotExist();
            }
            var newId = Convert.ToBase64String(Encoding.UTF8.GetBytes(blockIds.Count().ToString()));
            blob.PutBlock(newId, new MemoryStream(byteArray), null);
            blockIds.Add(newId);
            blob.PutBlockList(blockIds);
        }
        catch (Exception ex) 
        { 
            UT.ExceptionReporting(ex, "Error in Updating Backup Blob - writing byte array to blob"); 
        }
    }
}
catch (Exception ex) 
{ 
    UT.ExceptionReporting(ex, "Error in Updating Backup Blob - creating XmlWriter"); 
}
}
catch (Exception ex) 
{ 
    UT.ExceptionReporting(ex, "Error in Updating Backup Blob - getting container and blob references, serial no -" + serialNo); 
}

This works for 10 blocks, then on the 11th block it fails with the following error: -

StorageClientException - The specified block list is not valid.

InnerException = {"The remote server returned an error: (400) Bad Request."}

I searched the Internet for messages about the same error, but no luck.

Any help would be greatly appreciated.

+5
source share
3 answers

For this blob, the length of the value specified for the blockade parameter must be the same size for each block.

http://msdn.microsoft.com/en-us/library/windowsazure/dd135726.aspx

10 0 9. 11- - 10, . , . , , , .

, , , .

+14

BlockID

var blockIdBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(blockId.ToString(CultureInfo.InvariantCulture).PadLeft(32, '0')));
+2

, 10 (Error 400).

  • Encoding.UTF8.GetBytes System.BitConverter.GetBytes string blockIdBase64=Convert.ToBase64String(System.BitConverter.GetBytes(x++)); blockIDs . BitConverter.GetBytes .
  • (Error 400). temp blob "Azure storage explorer". .
0

All Articles