Invoke-RestMethod fails on very large files
See original GitHub issueIt seems Invoke-RestMethod fails to download very large files, probably due to not enough memory.
Steps to reproduce
Invoke-RestMethod -Uri http://speedtest.tele2.net/10GB.zip -OutFile /Users/ffeldhaus/Downloads/10GB.zip
Expected behavior
Very large files should be downloaded without issues.
Actual behavior
PS /Users/ffeldhaus/development> Invoke-RestMethod -Uri http://speedtest.tele2.net/10GB.zip -OutFile /Users/ffeldhaus/Downloads/10GB.zip
Invoke-RestMethod : Stream was too long.
At line:1 char:1
+ Invoke-RestMethod -Uri http://speedtest.tele2.net/10GB.zip -OutFile / ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Invoke-RestMethod], IOException
+ FullyQualifiedErrorId :
System.IO.IOException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
Environment data
Mac OS X 10.12.5
PS /Users/ffeldhaus/development> $PSVersionTable
Name Value
---- -----
PSVersion 6.0.0-beta
PSEdition Core
BuildVersion 3.0.0.0
CLRVersion
GitCommitId v6.0.0-beta.2
OS Darwin 16.6.0 Darwin Kernel Version 16.6.0: Fri Apr 14 16:21:16 PDT 2017; root:xnu-3789.60.24~6/RELEASE_X86_64
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Issue Analytics
- State:
- Created 6 years ago
- Comments:22 (10 by maintainers)
Top Results From Across the Web
Having trouble uploading large files with Invoke-RestMethod
I am trying to use the Hashicorp Atlas restful api to upload box files into but I am running into problems when uploading...
Read more >windows server 2012 r2 - Download big files with PowerShell
Invoke -WebRequest was designed for small files and it's speed is very slow. Note that BITS can show progress, because Write-Progress cmdlet can ......
Read more >Invoke-WebRequest large file upload - underlying ...
I'm trying to upload a large file to Nexus repo using Invoke-WebRequest and getting the following error message.
Read more >Invoke-RestMethod - PowerShell
The Invoke-RestMethod cmdlet sends HTTP and HTTPS requests to Representational State Transfer (REST) web services that return richly structured data.
Read more >Invoke-RestMethod fails when the powershell is run from ...
Hi, I have a developer who has a working Invoke-RestMethod when its run from any other server but fails when its run from...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@daxian-dbw Thanks for remainder! It seems BufferingStreamReader class has an issue. Also I discovered that Ctrl-C doesn’t work in Invoke-RestMethod for the large file download scenario. So I pulled a PR to resolve both issues.
I tried 7.0 Preview5 without any issue:
It was 9.4 Gb and was long but no memory issues and no exceptions.