C
C#2y ago
kolya112

❔ 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
Thinker
Thinker2y ago
Is there a reason you're using WebClient?
kolya112
kolya112OP2y ago
No, I have been using it for a long time, although I know that it is outdated. What can you recommend for a replacement?
Thinker
Thinker2y ago
HttpClient Essentially you just do this
HttpClient client = new();
var response = await client.GetAsync(url);
var file = await Response.Content.ReadAsByteArrayAsync();
HttpClient client = new();
var response = await client.GetAsync(url);
var file = await Response.Content.ReadAsByteArrayAsync();
kolya112
kolya112OP2y ago
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?
Thinker
Thinker2y ago
If you await everything properly then it shouldn't be an issue Anywhere something returns a Task, you await it.
kolya112
kolya112OP2y ago
Thx
kolya112
kolya112OP2y ago
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"
Thinker
Thinker2y ago
hmm
Tvde1
Tvde12y ago
sounds like something is wrong with the web server
kolya112
kolya112OP2y ago
The browser downloads them perfectly. All 1.5 and 1.4 GB. And C# only +- 1.05 GB and then gives an error.
Anton
Anton2y ago
Are you sure this doesn't load the whole thing into memory first?
mindhardt
mindhardt2y ago
Consider doing HttpClient.GetAsStreamAsync Not sure if it helps tho
Accord
Accord2y ago
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.
Want results from more Discord servers?
Add your server