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

438
Views
NestJS/Express devuelve un archivo PDF desde una URL externa en respuesta

Estoy llamando a una API externa que devuelve un archivo PDF y quiero devolver este archivo PDF en la respuesta de mi función de controlador.

En mi clase de controlador:

 @Get(':id/pdf') async findPdf(@Param('id') id: string, @Res() res: Response) { const response = await this.documentsService.findPdf(id); console.log(response.data); // this prints the following: // %PDF-1.5 // %���� // 2 0 obj // << /Type /XObject /Subtype /Image /ColorSpace /DeviceRGB /BitsPerComponent 8 /Filter // /DCTDecode /Width 626 /Height // 76 /Length 14780>> // stream // and go on... return res .status(200) .header('Content-Type', 'application/pdf') .header('Content-Disposition', response.headers['content-disposition']) .send(response.data); }

En Mi clase de servicio:

 findPdf(id: string): Promise<any> { return firstValueFrom( this.httpService .get(`/docs/${id}/pdf`) .pipe(map((response) => response)) .pipe( catchError((e) => { throw new BadRequestException('Failed to get PDF.'); }), ), ); }

Sin embargo, recibo un archivo PDF en blanco en mi respuesta.

La llamada a la API interna funciona bien, la probé desde Postman y el archivo PDF es correcto.

¿Qué estoy haciendo mal?

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!