0

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?

Nkosi
  • 235,767
  • 35
  • 427
  • 472
Pavlo Datsiuk
  • 1,024
  • 9
  • 17
  • 1
    So you have the issue with bad Wifi. With good LAN connection there's no issue. What could be the issue?? – user743414 Jan 29 '18 at 10:31
  • I've tried 3 different wifi spots with different ISP. I don't it is a case with bad wifi, because, on other websites, I can easily download any file with any size. – Pavlo Datsiuk Jan 29 '18 at 10:57