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

371
Views
Cómo mostrar un archivo pdf devuelto desde la API REST en una ventana emergente

Tengo una API REST que devolverá un archivo en una cadena base64. Ya he podido volver a convertirlo en datos de archivo para permitir que el usuario descargue el archivo en el lado del cliente al hacer clic en el enlace. El código es el siguiente:

 if(link !== undefined && link !== null && link.trim() !== ""){ var setting = []; var urlGet = link; //example: "../API/fileDownload?directory=AAA&filename=BBB.pdf"; const httpGet = new XMLHttpRequest(); httpGet.open('GET', urlGet, false); httpGet.send(); var returnText = httpGet.responseText; var returnStatus = httpGet.status; if(returnStatus == "200"){ setting = JSON.parse(returnText); } if(setting !== undefined && setting !== null ){ var filename = setting.filename; var data = setting.data; var content = setting.content; var hiddenElement = document.createElement('a'); hiddenElement.href = 'data:' + data + ';base64,' + content; hiddenElement.target = '_blank'; //provide the name for the file to be downloaded hiddenElement.download = filename; hiddenElement.click(); } }

Sin embargo, ahora me pidieron que agregara una función que abrirá el archivo en una ventana emergente si es un pdf. Ignore la verificación para ver si el archivo es pdf (solo asuma que todos los archivos serán pdf), ¿puede ayudarme a cambiar el código anterior para hacer esto?

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!