Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

276
Views
ASP.NET Web API devuelve el archivo de Excel al cliente

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.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!