Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

369
Visualizações
How to display a pdf file return from REST API in pop-up

I have a REST API that will return a file in base64 string. I have already be able to convert it back to file data to let user download the file in client-side when click on the link. The code is as below:

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();
    }
}

However, now, I was ask to add a function that will open the file in a pop-up if it is a pdf. Let ignore the check to see if the file is pdf (just assume all files will be pdf), can you help me change the above code to do this.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda