I have aspnetcore website hosted on Azure. The website has mvc controller method for downloading zip achieve on the fly.
Here's example of method, an idea is very simple:
[Authorize(Roles = Roles.Supplier)]
[HttpGet("Download/{orderId}")]
public async Task<IActionResult> DownloadAsync(int? orderId)
{
if (orderId == null)
{
return NotFound();
}
var order = await _context.Orders.Where(w=>w.id == orderId);
if (order == null)
{
return NotFound();
}
var filesToZip = GetFilepathInZip(order.Details);
return new FileCallbackResult(new MediaTypeHeaderValue("application/octet-stream"),
async (outputStream, _) =>
{
using (var zipArchive = new ZipArchive(new WriteOnlyStreamWrapper(outputStream), ZipArchiveMode.Create))
{
foreach (var kvp in filesToZip)
{
var zipEntry = zipArchive.CreateEntry(kvp.PathInZip, CompressionLevel.NoCompression);
using (var zipStream = zipEntry.Open())
using (var m = new MemoryStream())
using (var fileStream = new FileStream(kvp.PathAtServer, FileMode.Open))
{
await fileStream.CopyToAsync(zipStream);
}
}
}
})
{
FileDownloadName = string.Format("Archive_{0}.zip", order.Id)
};
}
Every time, when I use slow wi-fi connection for a file downloading, connection to the server break and I got the broken file.
But with fast LAN connection, this issue was not happening.
No issue in app insights. I'm using shared infrastructure.
What could it be?