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

309
Views
Descargar archivo en Angular 2 (la ventana emergente de descarga no aparece)

Tengo un botón de vista y al hacer clic llamo a la API web para descargar el archivo del documento de Word.

WebAPI funciona bien, cuando pego la URL de descarga en el navegador (por ejemplo , http://localhost:50963/api/Download/1022 ), el navegador muestra una ventana emergente para guardar/cancelar. ingrese la descripción de la imagen aquí

Quería tener el mismo comportamiento, es decir, cuando el usuario hace clic en el botón Ver, necesito mostrar la ventana emergente de descarga anterior. La API se está llamando con éxito, vea la siguiente captura de pantalla ingrese la descripción de la imagen aquí

descargar.servicio.ts

 export class DownloadService { constructor(private http: Http) {} private downloadUrl = 'http://localhost:50963/api/Download/'; //Fetch all existing Templates DownloadDocument(Doc_Id: number){ return this.http.get(this.downloadUrl + Doc_Id.toString()) } }

documento-lista.componente.ts

 DownloadArticle(Doc: ArticleModel){ console.log("inside downloadarticle()",Doc.Doc_Id); this.downloadservice.DownloadDocument(Doc.Doc_Id) .subscribe( err => { console.log(err); }); }
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Tienes que hacer alguna solución aquí. El servicio angular 'http' no puede dar lo que desea. Pegué todo mi código viable aquí. Tienes que elegir la parte de tu necesidad.

 retrieveJquery(fileId: number, fileName: string): void { let that = this; let useBase64 = false; let iOS = false; if (navigator.platform) iOS = /iPad|iPhone|iPod/.test(navigator.platform); else if (navigator.userAgent) iOS = /iPad|iPhone|iPod/.test(navigator.userAgent); let android = false; if (navigator.platform) android = /android/.test(navigator.platform); else if (navigator.userAgent) android = /android/.test(navigator.userAgent); //useBase64 = iOS; if (iOS || android) { window.open('cloud/api/file/retrieve?fileId=' + fileId + '&base64=-1&_access_token=' + this.utilsSvc.getToken(), '_blank'); } else { $.ajax({ type: "GET", headers: { 'Authorization': this.utilsSvc.getToken() }, url: 'cloud/api/file/retrieve', data: { 'fileId': fileId, 'base64': useBase64 ? '1' : '0' } , xhrFields: { responseType: 'blob' } }).fail(function (jqXHR, textStatus) { if (jqXHR.status === 501) alert('Please configure service url first.'); else if (jqXHR.status === 404) alert('File not found'); else alert('Retrieving file failed: ' + textStatus + " : " + jqXHR.responseText); }).done(function (data) { if (useBase64) window.open('data:' + that.utilsSvc.getMimeType(fileName) + ';base64, ' + data, '_blank'); else { let blob = new Blob([data]); if (window.navigator && window.navigator.msSaveOrOpenBlob) window.navigator.msSaveOrOpenBlob(blob, fileName); else { let link = document.createElement('a'); link.target = '_blank'; link.href = window.URL.createObjectURL(blob); link.setAttribute("download", fileName); link.click(); } } }); } }
over 4 years ago · Santiago Trujillo 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!