locked
CloudAppendBlob AppendTextAsync keeps overwriting my blob data, not appending it RRS feed

  • Question

  • I am attempting to use the new CloudAppendBlob in the latest C# Azure Storage library (5.0.0 stable and 5.0.1-preview) but my unit tests keep failing when using the AppendTestAsync method. Whenever I run my unit tests with the Async call (see below) the data appears to get overwritten, not appended i.e. the blob only contains the last string written to it.

    await appendBlob.AppendTextAsync(base64EncodedBson + Base64Delimitter);

    Using the call below works fine though, albeit I cannot take advantage of async code.

    appendBlob.AppendText(base64EncodedBson + Base64Delimitter);

    Am I missing something or is this a bug in the library? I tried searching on GitHub but nothing obvious shows itself:

    Azure Storage repo on Github

    I'm running the tests from a class library project in the latest version of VS2015.

    • Moved by Kristin Xie Tuesday, August 25, 2015 2:07 AM move to appropriate forum
    Monday, August 24, 2015 3:41 PM

Answers

All replies

  • Hi Roger,

    According to your description, your case more related to Azure Storage, I will move your case

     

    Microsoft AzureAzure Storage forum for better support.

    Best regards,

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, August 25, 2015 2:06 AM
  • Hi RogerD7,

    Thanks for posting here.

    Similar thread which was posted a week ago,and as of now AppendBlob is not supported on Azure.

    https://social.msdn.microsoft.com/Forums/azure/en-US/fcbfab79-5977-4418-baae-1002dce68907/when-creating-an-appendblob-i-cant-see-it-409-conflict?forum=windowsazuredata

    Girish Prajwal

    Wednesday, August 26, 2015 12:21 PM
  • Hi Girish,

    AppendBlob is supported in Azure, here is the release information on it going to general availability:

    MS Azure Storage Blog - AppendBlob GA

    The guy, Amir, in the post you suggest seems to be complaining he cannot see the AppendBlob in the Management Portal or Storage Explorer which is not the same as my problem.

    The issue I have is AppendTextAsync overwrites my blob, rather that appends to it. AppendText (no async) appends to my blob though, as do the other byte based methods so I'm happy that AppendBlob is working, its just the AppendTextAsync method that looks to be buggy.

    Many Thanks,

    Roger

    Thursday, August 27, 2015 8:44 AM
  • Hi RogerD7,

    Please describe more details of the error you're encountering (including but not limited to: exception type, message and stack trace) so that we can provide further help.

    Best Regards,

    Zhaoxing Lu

    Tuesday, September 1, 2015 2:01 AM
  • Hi Zhaoxing,

    if you read my original posting, there is no exception generated and thus no stack trace to report. If you use the await appendBlob.AppendTextAsync method call the existing blob data gets overwritten (this is incorrect behaviour), but if you use the appendBlob.AppendText method call the data gets appended to the existing blob (as expected).

    Run the code below as a console app and it demonstrates what I am seeing. You should see these results below, which shows the append async method has overwritten, not appended:

    Append blob of name appendblob, length 200, contents: Appended Text No 0, Appended Text No 1, Appended Text No 2, Appended Text No 3, Appended Text No 4, Appended Text No 5, Appended Text No 6, Appended Text No 7, Appended Text No 8, Appended Text No 9,
    Append blob of name appendblobasync, length 26, contents: Appended Async Text No 9,

    Many Thanks,

    Roger

    private static void Main(string[] args)
    {
        const string appendAsyncBlobName = "appendblobasync";
        const string appendBlobName = "appendblob";
        var connString = "Add your storage connection string here";
        var storageAccount = CloudStorageAccount.Parse(connString);
        var blobClient = storageAccount.CreateCloudBlobClient();
    
        // Retrieve a reference to a container. 
        var blockContainer = blobClient.GetContainerReference("appendblobtest");
    
        // Create the container if it doesn't already exist.
        blockContainer.CreateIfNotExists();
    
        // append data to the blob asynchronously
        AppendTextAsync(blockContainer, appendAsyncBlobName).Wait();
    
        // now do the same for the same but use the non-async method
        AppendTextNonAsync(blockContainer, appendBlobName);
    
        DisplayContainerContents(blockContainer);
    
        Console.ReadKey();
    }
    
    /// <summary>
    /// Appends the text asynchronously
    /// </summary>
    /// <param name="blockContainer"></param>
    /// <param name="appendAsyncBlobName"></param>
    /// <returns></returns>
    private static async Task AppendTextAsync(CloudBlobContainer blockContainer, string appendAsyncBlobName)
    {
        var appendAsyncBlob = blockContainer.GetAppendBlobReference(appendAsyncBlobName);
    
        // delete the append blob
        appendAsyncBlob.CreateOrReplace();
    
        const int loopCount = 10;
    
        for (int i = 0; i < loopCount; i++)
        {
            await appendAsyncBlob.AppendTextAsync($"Appended Async Text No {i}, ");
        }
    }
    
    /// <summary>
    /// Appends the text non-asynchronously
    /// </summary>
    /// <param name="blockContainer"></param>
    /// <param name="appendBlobName"></param>
    /// <returns></returns>
    private static void AppendTextNonAsync(CloudBlobContainer blockContainer, string appendBlobName)
    {
        var appendBlob = blockContainer.GetAppendBlobReference(appendBlobName);
    
        // delete the append blob
        appendBlob.CreateOrReplace();
    
        const int loopCount = 10;
    
        for (int i = 0; i < loopCount; i++)
        {
            appendBlob.AppendText($"Appended Text No {i}, ");
        }
    }
    
    /// <summary>
    /// Displays the contest of the blobs in the container
    /// </summary>
    /// <param name="container"></param>
    private static void DisplayContainerContents(CloudBlobContainer container)
    {
        // Loop over items within the container and output the length and URI.
        foreach (IListBlobItem item in container.ListBlobs(null, true))
        {
            if (item is CloudAppendBlob)
            {
                var blob = (CloudAppendBlob) item;
    
                Console.WriteLine(
                    $"Append blob of name {blob.Name}, length {blob.Properties.Length}, contents: {blob.DownloadText()}");
            }
            else if (item is CloudBlockBlob)
            {
                Console.WriteLine("This is a block blob");
            }
            else if (item is CloudPageBlob)
            {
                Console.WriteLine("This is a page blob");
            }
            else if (item is CloudBlobDirectory)
            {
                Console.WriteLine("This is a blob directory");
            }
        }
    }


    Tuesday, September 1, 2015 10:07 AM
  • Hi Roger -

    Thank you for reporting this - it is indeed a bug. We have posted an updated nuget package and update source code on GitHub.

    http://blogs.msdn.com/b/windowsazurestorage/archive/2015/09/02/issue-in-azure-storage-client-library-5-0-0-and-5-0-1-preview-in-appendblob-functionality.aspx

    Please let us know if you have any further issues.

    Thanks

    Jason


    jason

    • Marked as answer by RogerD7 Wednesday, September 2, 2015 8:04 AM
    Wednesday, September 2, 2015 3:15 AM
  • Thanks for the quick resolution Jason, I've updated to the latest preview package, 5.0.3, and my unit tests are now passing with the AppendTextAsync method.

    Many Thanks,

    Roger

    Wednesday, September 2, 2015 8:04 AM
  • Thanks for the acknowledgement Roger. 

    thanks

    Dinesh

    Wednesday, September 2, 2015 9:40 PM