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