Is there way to track the file upload progress to an Azure storage container? I am trying to make a console application for uploading data to Azure using C#.
My c
How about this.
public class ObservableFileStream : FileStream
{
private Action _callback;
public ObservableFileStream(String fileName, FileMode mode, Action callback) : base(fileName, mode)
{
_callback = callback;
}
public override void Write(byte[] array, int offset, int count)
{
_callback?.Invoke(Length);
base.Write(array, offset, count);
}
public override int Read(byte[] array, int offset, int count)
{
_callback?.Invoke(Position);
return base.Read(array, offset, count);
}
}
public class Test
{
private async void Upload(String filePath, CloudBlockBlob blob)
{
ObservableFileStream fs = null;
using (fs = new ObservableFileStream(filePath, FileMode.Open, (current) =>
{
Console.WriteLine("Uploading " + ((double)current / (double)fs.Length) * 100d);
}))
{
await blob.UploadFromStreamAsync(fs);
}
}
}