Adding Data to a existing AppendBlob/Block BLOB

Ashutosh Saini 31 Reputation points

Is it possible to add rows to an existing append/Block blob in premium tier. We are facing issues that if we try to add it overrides the older data and in the end only 1 record in present which is updated in the last.

We need to write data to a file from multiple instances of the application which will be receiving data from event hub.

Using Java we tried below approach but didn't work:

BlobClient blobClient = containerClient.getBlobClient("appendBlobTest.txt");
        AppendBlobClient appendClient = blobClient.getAppendBlobClient();

        InputStream stream = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8));
        appendClient.appendBlock(stream, data.length());
Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,285 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. shiva patpi 12,961 Reputation points Microsoft Employee

    Hello @Ashutosh Saini ,
    Thanks for reaching out to Microsoft Q&A platform.
    You can't append to Block Blob but I just tried for Append Blob using , below is the piece of tested code and it works by appending to the existing file. I am sure similar functions will work for Java SDK too, modify the code accordingly to get your stream. Please try out.

        public static void AppendToBlobStorage()  
            string connection = "DefaultEndpointsProtocol=https;AccountName=accountname;AccountKey=accountkey;";  
            string filename = "appendblob.txt";  
            string container= "test";  
            CloudStorageAccount storage = CloudStorageAccount.Parse(connection);  
            CloudBlobClient client = storage.CreateCloudBlobClient();  
            CloudBlobContainer container = client.GetContainerReference(container);  
            CloudAppendBlob blob = container.GetAppendBlobReference(filename);  
            using (MemoryStream stream = new MemoryStream())  
            using (StreamWriter sw = new StreamWriter(stream))  
                sw.WriteLine("This is appended line");  
                stream.Position = 0;  

    If that helps out , kindly make sure to Upvote & Accept the answer.

    1 person found this answer helpful.

  2. SaiKishor-MSFT 17,141 Reputation points

    @Sergey Shabalov Thanks for reaching out to Microsoft Q&A. I understand that you are having issues with appending data to your storage file.

    I read through your code and itseems like right now, this code is attempted to append and flush to the same offset over and over again. The offsets for the Append and Flush needs to be updated each iteration of that loop. Checkout the DatalakeClient.AppendAsync method and the offset parameter to understand better here-

    Please let us know if you have any more questions and we will be glad to assist you further. Thank you!


    Please accept an answer if correct. Original posters help the community find answers faster by identifying the correct answer. Here is how.

    Want a reminder to come back and check responses? Here is how to subscribe to a notification.

    0 comments No comments