question

rhyuhsa-4355 avatar image
0 Votes"
rhyuhsa-4355 asked rhyuhsa-4355 commented

Adding Data to a existing AppendBlob/Block BLOB

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");
         //blobClient.
         AppendBlobClient appendClient = blobClient.getAppendBlobClient();
            
         InputStream stream = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8));
         appendClient.appendBlock(stream, data.length());
azure-blob-storage
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

shivapatpi-MSFT avatar image
0 Votes"
shivapatpi-MSFT answered rhyuhsa-4355 commented

Hello @rhyuhsa-4355 ,
Thanks for reaching out to Microsoft Q&A platform.
You can't append to Block Blob but I just tried for Append Blob using C#.net , 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;EndpointSuffix=core.windows.net";

         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");
             sw.Flush();
             stream.Position = 0;
             blob.AppendFromStream(stream);
         }
     }


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

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I tried but not able to find the similar way as you mentioned apart from what i tried above using java..!!

0 Votes 0 ·