您如何在 web api 中将文件的一部分作为流读取并对该流执行操作而不将整个文件放入内存中?注意:我不想在阅读之前将文件保存在任何地方 - 它已上传到 Web api 控制器。
但我真正想要的是实现以下伪代码:
foreach file in Request
{
using (var sr = new StreamReader(fileStream))
{
string firstLine = sr.ReadLine() ?? "";
if (firstLine contains the magic I need)
{
// would do something with this line,
// then scrap the stream and start reading the next file stream
continue;
}
}
}