0
如何在web api中将文件的一部分读取为流并对此流执行操作而不将整个文件存储在内存中?注意:我不想在阅读之前将文件保存到任何地方 - 它会上传到web api控制器。Web API 2 - 流读取文件
但我真正想为实现以下伪代码:
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;
}
}
}
如果文件未保存,则表示是内存。否则,你不可能读取文件 – Tinwor
因此,发布控制器时,从头开始将整个文件存储在内存中? – user2330270
它不从客户端流? – user2330270