Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Comercial
    • Calculadora

0

13
Vistas
Streaming a file from URL in smaller chunks from a controller back to view for client to download

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.

7 months ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos