I am looking to Stream a file from an internally generated URL(i.e http://192.168.x.x/download/filekeylink) to a user to download. The way I have it set up is the user hits the download button which sends a WEBAPI POST request to the controller which then hits an API that gets the URL with the file ready. The problem here is while I have experience loading local files from paths, I haven't ever streamed a file from a URL before and I was told this is possibly better than storing it in memory(can't store it locally)
js
async downloadAttach(ID: any) {
window.open(await ApiFunc.post('Ticket', 'Download', CommID));// my own API call fucntion that works.
}
Controller
[Route("api/Ticket/Download")]
[HttpPost]
public async Task<//Streamed file> Download([FromBody]string uri)
{
//Returning the streamed file to user to download
}
What is the best practice around this(avoiding storing file locally or storing it in memory first). I have seen some people using
HttpWebRequest
However I am unsure that fits my needs as it seems this utilises the need to access the internal url(I could be wrong but when I tried it, it failed.)
For example this code here by Dallas:
Download/Stream file from URL - asp.net
I'm trying to understand how this would return to the client view and start the download in their browser without a return value. Is it because instead it would be using a GET API?