I have an ASP.NET Core app. There is a report created from data in DB that can be potentially several gigabytes in size.
Is it possible to stream data as a response from WebAPI in chunks, so that memory usage on server is minimized?
A very rough idea of what I want is
[HttpGet]
public IActionResult HugeReport()
{
Response.ContentType = "text/plain";
StreamWriter sw = new StreamWriter(Response.Body);
var doc = new SpreadsheetDocument();
for (int i = 0; i < 100; i++)
{
var data = Db.Skip(i * 1000).Take(1000);
doc.WorkbookPart.AddData(data);
}
}
Or, if this approach is not possible, can I construct a file in file system in chunks, iteration by iteration (without loading whole document to memory)?