Search code examples
windowsazureazure-storageblobs

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)

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.