-
Notifications
You must be signed in to change notification settings - Fork 7.6k
WebClient needs to expose the timeout property (or improve Invoke-WebRequest implementation) when downloading large files #4679
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
Comments
@markekraus Is the Issue already fixed? |
No. we added a resume feature but not a way to timeoul a download. This is, however, something we could add. Since we do a looped read of the stream, we could insert logic in their to stop when the time out is reached. |
Ah, I again confused these two PR. |
@stevenebutler This issue can be fixed with the |
This issue touches several problems but the main request is "What I needed is a way to stream the remote file to a local file without loading everything into memory." Does this problem still exist and in what specific scenarios? |
There are two problems here:
|
If so we should close the issue.
It is another request. I think it makes no sense. Otherwise we will have to add timeouts in all cmdlets like Copy-Item, Get-Content and so on. If you want to discuss this please open new issue. |
This issue has been marked as fixed and has not had any activity for 1 day. It has been closed for housekeeping purposes. |
@CarloToso starting what version does the download streaming work by design, please? Thanks! |
I tested it works correctly in 5.1, 7.2, 7.3, 7.4. I hypotesize it was fixed before 6.1, but I didn't check. |
I have been having some issues interacting with REST full APIs, specifically with our product (Pexip) which is writing with Python and Django and uses Apache. Some of these issues are outlined in #2112 and #4274 and this involves a similar an linked problem. I also added a comment to https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-webrequest?view=powershell-5.1 that outlines this issue that I have repeated below:
Attempting to download a large file, GETting from a REST API.
The Basic Invoke-WebRequest
This would be the ideal. I can set timeout values and seemingly achieve what I want in one line. Unfortunately, this completely locked up the machine the script was running on. Basically, all the memory was consumed and after an hour or so, I had to end the script – of the 3.5 GB file, I think 200 MB was downloaded! What I needed is a way to stream the remote file to a local file without loading everything into memory.
Using WebClient
This seemed a lot better, however, the WebClient has no timeout property!!!
This is what I ended up using and in order to get the timeout to work, I used an extended class – luckily someone clever than I has achieved this for PowerShell using a C# class (https://koz.tv/setup-webclient-timeout-in-powershell/) although I assume the native classes in PS could also be used – but why?
I have also found that I must add the additional Authorisation Headers, otherwise the client will get challenged then end up download the file effectively twice. Using Fiddler and watching the Ethernet stats, you can see this happen. Indeed, this seemingly occurred for all methods
Using HTTP client.
Well I tried and failed dismally. However, I seem to create the Httpclient, it only ever seemed to stream the remote file into memory before dumping to a file. I know what I wanted to do, but do not have the wherewithal to do it.
The text was updated successfully, but these errors were encountered: