Repository navigation
Description
Summary of the new feature / enhancement
I would like an ability to download a file with Invoke-WebRequest without explicitly providing its name, same as with curl -O. The filename should be deduced from the uri, equivalent to -Uri $Uri -OutFile (Split-Path $Uri). If the uri contains query parameters, they are either discarded (test.txt?param=value results in test.txt), or an error should be given.
Motivating example can be seen in Invoke-WebRequest example #8, the filename is typed twice for every file - once in Uri and once in OutFile.
Additionally, I think that -OutLeaf without -PassThru should return the full resolved path to the downloaded file, so that it can be stored or piped into Start-Process or Invoke-Command for immediate execution (useful for e.g. installers).
Similar proposals were made in:
- Allow downloading multiple files with Invoke-WebRequest #17554 - Closed due high complexity
- allow to download file to specified folder with Invoke-WebRequest #17553 - Closed due overzealous @msftbot
I agree with the latter, that -OutDirectory could be an alternative API, so that you can get Invoke-WebRequest -OutLeaf with Invoke-WebRequest -OutDirectory ., while also allowing to download files with implicit filename to a different directory.
Opens:
- Should the filename be url-decoded? I.e. should
Invoke-WebRequest example.com/file%20with%space.txt -OutLeafresult infile%20with%20space.txtorfile with space.txt? I would say latter,curlsays former.
Proposed technical implementation details (optional)
No response
Activity
CarloToso commentedon Jul 22, 2023
Similar to #11671, partially addressed by #19007 and #19385
dkaszews commentedon Jul 22, 2023
Does #19007 mean you can just specify a directory with
-OutFileand it will just work as I described? I did not see anything about it in documentation.CarloToso commentedon Jul 22, 2023
Yes, but it's still being worked on so it could not work as expected in some cases.