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

145
Visualizações
application/json served from API to frontend save PDF with correct number of pages but no content

After a request to an API, I get a PDF as a response. I then pass this response to the frontend for the user to print, however on the frontend I only manage to get a PDF with the correct number of page, but all the pages are blank.

Here is the request:

const streamResponse = await axios({
    url : endpoint_url,
    method: 'GET',
        headers: {
            some authorization parameters,
        },
        responseType: 'stream'
    });
        
    streamResponse.data.pipe(res)

On the frontend I have this code:

let blob = new Blob([res.data], { type: "application/pdf" });
let link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = 'output.pdf';
link.click();

I also tried to use the file-saver library to directly save the PDF but I get the same result. The data in the response is something like that :

"%PDF-1.4
%����
4 0 obj
<</Filter/FlateDecode/Length 1379>>stream
x���]s�6����3�N�,���%���N����Nn,۴|8|$�_IX a�����$A���WGGΛv>�6�fs̀�#���%d�l����ٿ�ݐ�덦S�L@#&b=$K��>���y�dOd'Y�]��7EV�7X?�h�>`_�
�t%�=��,����!N3Pm,�Ɠ�{�tPYb`������P�jVڭJR����c5�ي��N�$� i�8�Oqlt����wg�#����$�-gC�%��&$Q���q�@���>� �W�i��Ż+TM��s���&uÀk�x$(��|I)8�S^̑�M��y���Na���<)&���hq��D^�̏#HW�G�5~'�M� .......

I know that it is a valid PDF file because I am able to save it on the server, but I cannot find anyway to serve it to the client side.

I also tried to save it in the server and then using a request using the below code to serve it to the client:

let pdfFile = fs.createReadStream(pdfFilePath)
res.setHeader('Content-Type', 'application/pdf')
pdfFile.pipe(res);
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