❔ Problem with WebClient
Downloading a file using DownloadFile(). What can limit file upload size via WebClient? There are files with a size of 1.4 and 1.5 GB (they have the same size on the server), they are loaded correctly in the browser, but from under the code, via WebClient.DownloadFile() - no, only +- 1.05 GB is loaded
13 Replies
Is there a reason you're using WebClient?
No, I have been using it for a long time, although I know that it is outdated. What can you recommend for a replacement?
HttpClient
Essentially you just do this I have the names of the files to download (one by one) are taken from the array, the values of which are sorted out using foreach. Wouldn't async interfere with this?
If you await everything properly then it shouldn't be an issue
Anywhere something returns a
Task
, you await
it.Thx
The same thing happened. Initially, everything was fine, when suddenly the process of downloading both files stopped at the same one as on WebClient: 1.05 GB instead of 1.4 and 1.5 GB. I had a try catch block and threw an exception "System.IO.IOException" in System.dll - "An error occurred while copying the content to the stream"
hmm
sounds like something is wrong with the web server
The browser downloads them perfectly. All 1.5 and 1.4 GB. And C# only +- 1.05 GB and then gives an error.
Are you sure this doesn't load the whole thing into memory first?
Consider doing HttpClient.GetAsStreamAsync
Not sure if it helps tho
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.