-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Progress while downloading a large file with HttpClient #16681
Comments
There are no progress callback features of System.Net.Http.HttpClient. There are no plans to add this. The feature set of CoreFx HttpClient matches that of .NET Framework (Desktop). You can add this feature yourself by using the appropriate APIs to "download" content. For example, if you use the |
Thanks, @davidsh ! I actually found this after further googling: I addapted it and created this:
I picked the buffer size of 8192 after measuring the max bytes read in the call to I'm trying to download a fairly big file from Visual Studio Team Services ("TFS in the cloud"). One thing I found when developing / debugging, is that VSTS will close a connection if a minimum throughput isn't being reached. (see http://blogs.msdn.com/b/taylaf/archive/2010/02/10/team-foundation-server-unable-to-read-data-from-the-transport-connection-an-existing-connection-was-forcibly-closed-by-the-remote-host.aspx). Originally I was writing out to the console on every read, but that slowed things down too much and I'd eventually get a "connection was forcibly closed" exception. -Brian Eriksen |
You can use ProgressMessageHandler when creating httpclient as it has HttpSendProgress and HttpReceiveProgress methods to tell you current progress. Something like this:
|
@davidsh anything changed with reporting progress? |
This is a closed issue. There are no changes to reporting progress. My previous feedback is still accurate:
|
Well... there are no alternative to track the download progress? |
IMO there should be the ability to get progress and transfer speed out of the box with HttpClient for upload/download in a fashion similar to FluentFTP. Where you just pass I don't understand why there are no plans to add this to make everything nicer. Please consider re-opening this. Like in FluentFTP: /// <summary>
/// Class to report Http Transfer Progress (Up and Donwload)
/// </summary>
public class HttpProgress
{
/// <summary>
/// A value between 0-100 indicating percentage complete
/// </summary>
public double Progress { get; set; }
/// <summary>
/// A value representing the current Transfer Speed in Bytes per seconds
/// </summary>
public double TransferSpeed { get; set; }
/// <summary>
/// A value representing the calculated 'Estimated time of arrival'
/// </summary>
public TimeSpan ETA { get; set; }
/// <summary>Contructor for the class</summary>
public HttpProgress(double progress, double transferspeed, TimeSpan remainingtime)
{
Progress = progress;
TransferSpeed = transferspeed;
ETA = remainingtime;
}
/// <summary>
/// Convert Transfer Speed (bytes per second) in human readable format
/// </summary>
public string TransferSpeedToString()
{
var num = TransferSpeed > 0.0 ? TransferSpeed / 1024.0 : 0.0;
return num < 1024.0 ? $"{Math.Round(num, 2)} KB/s" : $"{Math.Round(num / 1024.0, 2)} MB/s";
}
}
Sounds like "We don't want to make HttpClient better because .NET Framework didn't support this" |
This seems to imply that people are going to use the old Although a variety of workarounds of Great ! Microsoft used a clever way to guide me to learn their source code ! |
Hi All,
Googling around I found that Windows.Web.Http.HttpClient provides a way to get progress of a download. Is there an way to get some kind of progress information when downloading a large file using ASP.NET Core's HttpClient?
Thanks,
-Brian
The text was updated successfully, but these errors were encountered: