An Append Blob is comprised of blocks and is optimized for append operations. When you modify an Append Blob, blocks are added to the end of the blob only, via the Append Block operation.
Append Blob is optimized for fast append operations, making it ideal for scenarios where the data must be added to an existing blob without modifying the existing contents of that blob (Eg. logging, auditing).
Steps to create storage account
- Log on to Azure Portal.
- Click on Browse and select Storage Account (Classic)
- Click on Add button.
- Provide the input and click on Create button.
Steps to create Append Blob and write content in the Blob
- Open Visual Studio.
- Create new console application.
- In Solution Explorer, right-click References, then click Manage NuGet Packages.
- Install WindowsAzure.Storage
- Add below reference in program.cs file,
- using Microsoft.WindowsAzure.Storage;
- using Microsoft.WindowsAzure.Storage.Auth;
- using Microsoft.WindowsAzure.Storage.Blob;
- Add the following code in Main() function.
- string accName = "[StorageAccountName]";
- string accKey = "[StorageAccountKey]";
-
-
- StorageCredentials creds = new StorageCredentials(accName, accKey);
- CloudStorageAccount strAcc = new CloudStorageAccount(creds, true);
-
-
- CloudBlobClient blobClient = strAcc.CreateCloudBlobClient();
-
-
- CloudBlobContainer container = blobClient.GetContainerReference("mycontainer");
-
-
- container.CreateIfNotExistsAsync();
-
- DateTime dateLogEntry = DateTime.Now;
-
- CloudAppendBlob appBlob = container.GetAppendBlobReference("appandtext.txt");
-
-
- if (!appBlob.Exists())
- {
- appBlob.CreateOrReplace();
- }
-
-
-
- appBlob.AppendText
- (
- string.Format(
- "{0} | Message for blob!!!\r\n",
- dateLogEntry.ToString()));
-
-
- Console.WriteLine(appBlob.DownloadText());
-
- Console.WriteLine("Press any key to continue...");
- Console.ReadKey();
Note
You cannot edit/modify the existing blocks of the blob. You can only append to the end of the blob.