使用带有进度跟踪的 Dropbox .NET 库下载文件
这使用 Dropbox .NET SDK 将文件从远程 path
的 Dropbox API 下载到本地文件 Test
,同时跟踪进度:
var response = await client.Files.DownloadAsync(path);
ulong fileSize = response.Response.Size;
const int bufferSize = 1024 * 1024;
var buffer = new byte[bufferSize];
using (var stream = await response.GetContentAsStreamAsync())
{
using (var file = new FileStream("Test", FileMode.OpenOrCreate))
{
var length = stream.Read(buffer, 0, bufferSize);
while (length > 0)
{
file.Write(buffer, 0, length);
var percentage = 100 * (ulong)file.Length / fileSize;
// Update progress bar with the percentage.
// progressBar.Value = (int)percentage
Console.WriteLine(percentage);
length = stream.Read(buffer, 0, bufferSize);
}
}
}