Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Append text to Blob in Azure

After looking at this tutorial on blobs: channel 9, I was thinking of using a blob container to save a bunch of tweets (storing the json of each tweet that is). Ideally I would like to create a blob reference for each hour of the day, and append new tweets to this blob as they come in. The issue is that the method UploadText(string) overwrites the existing content of the blob, is there an easy way to append text to an existing blob ?

Thanks!

        fun (json:string) ->  
                    let account = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("DataConnectionString"))
                    let blobs = account.CreateCloudBlobClient();
                    let tempBlob = blobs.GetBlobReference("tweets/2010-9-26/17/201092617.txt")
                    tempBlob.Properties.ContentType <- "text/plain"
                    tempBlob.UploadText(json)
like image 598
jlezard Avatar asked Dec 12 '22 19:12

jlezard


1 Answers

Azure now supports Append Blobs. When you create a new blob, you must define it as an Append Block. You can't append to existing block blobs.

Here's some simple code which you can use.

Append:

CloudAppendBlob appendBlob = container.GetAppendBlobReference("myblob.txt")
appendBlob.AppendText("new line");

Read:

appendBlob.DownloadText()

Technet contains a good tutorial on the subject. Also the official Azure documentation now includes help for using Append Blob.

like image 60
Mikael Koskinen Avatar answered Dec 22 '22 13:12

Mikael Koskinen