Tengo el código api de C# como se muestra a continuación. Funciona correctamente cuando ejecuto Visual Studio y lo implemento en el servidor IIS. Consumo esta api por javascript o Angualar en producción Front-end. Funciona sin problemas si el byte [] es de tamaño pequeño.
[HttpPost] [Route("TestDownload2")] public HttpResponseMessage TestDownload2() { UTF8Encoding utf8 = new UTF8Encoding(); byte[] data = new byte[Convert.ToInt32(ConfigurationManager.AppSettings["byteLength"].ToString())]; ByteArrayContent byteContent = new ByteArrayContent(data); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK); response.Headers.Add("Access-Control-Allow-Origin", "*"); response.Content = byteContent; response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = ConfigurationManager.AppSettings["byteLength"].ToString() + "Schedule Report.xlsx" }; HttpConfiguration config = GlobalConfiguration.Configuration; return response; }Esta aplicación generará un error si byte[] tiene un tamaño grande, como 2500. En la consola del navegador aparece net::ERR_CONNECTION_RESET 200 (OK). Intento otra forma de devolver otro tipo y configuración de IIS, pero no funciona.
Según entiendo,
Deberá establecer la configuración dentro de web.config
<configuration> <system.web> <!-- This will handle requests up to 5GB --> <httpRuntime maxRequestLength="5242880" timeout="3600" /> </system.web> </configuration>O bien, puede descargar en la memoria del navegador usando reportProgress y una vez que se hayan descargado todos los datos de Steam, puede pedirle al usuario directamente a través del botón habilitar para descargar al instante.
const req = new HttpRequest('POST', '/download/file', file, { reportProgress: true, observe: 'events' });espero que ayude