Question

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)
Was it helpful?

Solution

Page Blobs are the way to go for this need. (vs block blobs)

You create the blob with a Put Blob operation: http://msdn.microsoft.com/en-us/library/dd179451.aspx

Then you can add "pages" using a Put page operation: http://msdn.microsoft.com/en-us/library/ee691975.aspx

Page Blobs will amend the page(s) added with a put immediately, more accurately mimicking traditional file systems.

Block blobs are going to expect a more ridig construction, and require a two-phase submit/commit construction. Once compiled, you have to overwrite to ammend to the blob. Block blobs are designed for streaming of static (loose definition) content, vs as a read/write store. Page Blobs were added to support those scenarios.

OTHER TIPS

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.

You can try getting the list of committed blocks via the CloudBlockBlob.DownloadBlockList() method and then append the new content via CloudBlockBlob.PutBlock().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top