尝试使用 TIdHTTP 下载文件时出现"Out of memory while expanding memory stream"错误



我正试图使用Delphi 10.4中的标准TIdHTTPTIdSSLIOHandler组件从web服务器下载文件:

memorystream := TMemoryStream.Create;
http.request.useragent:='Mozilla/5.0 (Windows NT 5.1; rv:2.0b8) Gecko/20100101 Firefox/4.0b8';
http.HandleRedirects := True;
try
http.get('https://dl.nmkd.de/ai/clip/coco/coco.ckpt',memorystream);
except
on E:Exception do memo.lines.add(E.Message);
memo.lines.add(http.responsetext);
end;
application.ProcessMessages;
memorystream.SaveToFile('coco.ckpt');
memorystream.free;

我在备忘录中得到的回复是:

Out of memory while expanding memory stream
HTTP/1.1 200 OK

该文件的大小约为9 GB。

如何获得能够处理该大小的MemoryStream?我在电脑上安装了足够多的物理RAM。

与其将资源临时加载到内存,不如使用TFileStream直接将其加载到本地文件:

Stream := TFileStream.Create('coco.cpkt');
try
try
http.get('https://dl.nmkd.de/ai/clip/coco/coco.ckpt', Stream);
except
on E:Exception do memo.lines.add(E.Message);
end;
finally
Stream.Free;
end;

相关内容