Is there way to track File Upload progress to Azure storage container ?
I am trying to make a console application for uploading data to azure using C#.
My coode for now looks like :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Blob;
using System.Configuration;
using System.IO;
using System.Threading;
namespace AdoAzure
{
class Program
{
static void Main(string[] args)
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference("adokontajnerneki");
container.CreateIfNotExists();
CloudBlobClient myBlobClient = storageAccount.CreateCloudBlobClient();
CloudBlockBlob myBlob = container.GetBlockBlobReference("racuni.adt");
CancellationToken ca = new CancellationToken();
var ado = myBlob.UploadFromFileAsync(@"c:\bo\racuni.adt", FileMode.Open, ca);
Console.WriteLine(ado.Status); //Does Not Help Much
ado.ContinueWith(t =>
{
Console.WriteLine("It is over"); //this is working OK
});
Console.WriteLine(ado.Status); //Does Not Help Much
Console.WriteLine("theEnd");
Console.ReadKey();
}
}
}
This pice of code are working well, But I'll love to have some kind of progress bar, So users can see that there is tasks doing. Is there something build in in WindowsAzure.Storage.Blob namespace so I can use as rabbit from hat ?
How about this.
I don't think it's possible because uploading file is a single task and even though internally the file is split into multiple chunks and these chunks get uploaded, the code actually wait for the entire task to finish.
One possibility would be manually split the file into chunks and upload those chunks asynchronously using
PutBlockAsync
method. Once all chunks are uploaded, you can then callPutBlockListAsync
method to commit the blob. Please see the code below which accomplishes that:Gaurav's solution works well and is very similar to http://blogs.msdn.com/b/kwill/archive/2011/05/30/asynchronous-parallel-block-blob-transfers-with-progress-change-notification.aspx. The challenge with this code is that you are doing a lot of complex work with very little error handling. I am not saying there is anything wrong with Gaurav's code - it looks solid - but especially with network related communication code there are lots of variables and lots of issues that you have to account for.
For this reason I modified my original blog to use the upload code from the storage client library (under the assumption that the code coming from the Azure Storage team was more robust than anything I could write) and track progress using a ProgressStream class. You can see the updated code at http://blogs.msdn.com/b/kwill/archive/2013/03/06/asynchronous-parallel-block-blob-transfers-with-progress-change-notification-2-0.aspx.