gpt4 book ai didi

Powershell 3 : preventing excessive memory usage for webrequest

转载 作者:行者123 更新时间:2023-12-04 02:01:54 24 4
gpt4 key购买 nike

我编写了一个简短的脚本,可以让我下载文件。

Invoke-WebRequest -Uri $r2.Forms.Action -WebSession $myWebSession -OutFile $destination$filename

整个下载都缓冲在内存中,这对于较大的文件来说显然不是最佳选择。我想知道(但我找不到)一种方法/属性来防止这种情况并直接流到磁盘。类似于.NET 中的AllowWriteStreamBuffering。

Out of Memory Exception When Using HttpWebRequest to Stream Large File

感谢任何帮助!

最佳答案

似乎唯一的方法是使用 WebClient

$webclient = new-object System.Net.WebClient
$webclient.Credentials = new-object System.Net.NetworkCredential($id, $p, $url)
$webclient.DownloadFile($r2, $destination+$tempfile)

#rename tempfile
$filename = $webclient.ResponseHeaders["Content-Disposition"].SubString($webclient.ResponseHeaders["Content-Disposition"].IndexOf("filename=")+10).Replace("`"", "");
Rename-Item $destination$tempfile -NewName $filename

关于Powershell 3 : preventing excessive memory usage for webrequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28274708/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com