1

I am looking to stream a file in chunks from a URL to avoid memory issues(I cannot download the file locally at all and I cannot pass the URL to the client). My main issue that I cannot get passed is returning it to the view for and it starting a download for the user.

js

async downloadAttach(ID: any) {
    
    window.open(await ApiFunc.post('Ticket', 'Download', CommID));// my own API call fucntion that works. 

    
}

This code calls to the API in the C# Controller when a button is clicked. This API works for functions that I currently have in place.

Controller

[Route("api/Ticket/Download")]
        [HttpPost]
        public async Task<//Streamed file> Download([FromBody]string uri)
        {
            //Load file into stream in chunks recursively, to pass back to view
        }

This is the controller that takes the URI supplied from the view section and loads in chunks back to the client.

What is the best practice around this?( I am looking to chunk it out already to avoid memory issues). I have also seen uses of HttpWebRequest but I'm not exactly sure how it works out returning to the view.

HttpWebRequest

Example from: Download/Stream file from URL - asp.net

This is the example I have been looking over that splits it up into small chunks but Im unsure how to get it to return through to the view and download. I have coded it up and made the proper modifications to fit with the packages Im using but onclick nothing happens.

NathHU
  • 31
  • 2
  • Chunking is not going to reduce memory usage. Better to download compressed version of file using GZIP. – jdweng Feb 01 '22 at 17:23
  • @jdweng isn't that the point of streaming it to the client? Stream the first chunk clear the buffer load next stream it repeat? I thought this was possible to keep memory down. I can't download a file only way is to stream from a URL to the user. The file resides on an internal non-public server. – NathHU Feb 01 '22 at 17:29
  • The point of streaming is when errors occur so you do not have to keep downloading the entire data when error occur. Data is downloaded with a CRC for each chunk and when the CRC is bad the entire chunk has to be resent. With multiple hops the streaming does keep memory usage low on hops but not at the final destination. – jdweng Feb 01 '22 at 17:39
  • @jdweng the final destination being the web server? Not the client? Cause in this set up the final destination is the client. The whole idea is to keep memory usage down on the web server if multiple clients are downloading different files. Looks like I will have to look at a different way of doing it sadly. – NathHU Feb 01 '22 at 17:58
  • The server has to keep chunks until the client sends back the ACK which increase memory. Smaller chunks means more chunks need to be kept but each chunk is smaller in size. Download rate is faster than upload rate which means ACKs are returned at slower rate. – jdweng Feb 01 '22 at 18:06

0 Answers0