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

168
Views
Devolver archivo para descargar usando WebAPI HTTPGet to View(User)

Soy nuevo en el lado de Javascript y estoy tratando de averiguar cómo devolver un archivo a un usuario para que lo descargue desde un ApiController.

ApiController:

 public class TickController : ApiController { [Route("api/Tick/Download")] [HttpPost] public async Task<HttpResponseMessage> Download(string i) { string url = await GetURL("id00032912"); //this is hard coded until I properly work out how to get a value passed along from HttpGet HttpResponseMessage result = null; WebClient myClient = new WebClient(); byte[] bytes = myClient.DownloadData(url); result = Request.CreateResponse(HttpStatusCode.OK); result.Content = new ByteArrayContent(bytes); result.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment"); result.Content.Headers.ContentDisposition.FileName = "test" + ".txt"; return result; } }

Ahora el result se llena con los datos requeridos, pero no puedo lograr que regrese.

Uso esta llamada en JS para llamar y acceder a la función.

 await WebApi.getJSON('Tick', 'Download', ID);

Esta es la llamada WebApi expandida

 static getJSON(controller: string, action: string, querystring: string, data?: any): any { return this.get("api", controller, action, querystring, data); } static getODataJSON(controller: string, querystring: string, data?: any): any { return this.get("odata", controller, null, querystring, data); }

Mi problema es que no estoy seguro de cómo manejar correctamente el valor que se devuelve en Javascript y cómo forzar su descarga en el lado de los usuarios. Me preguntaba si alguien podría mostrar algunos ejemplos o indicarme la dirección correcta.

Cualquier ayuda sería apreciada gracias!.

NOTA Estoy usando ApiController, por lo que no puedo usar return File () como lo hacen muchas otras preguntas similares.

about 4 years ago · Juan Pablo Isaza
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!