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

223
Views
Serverless API Gateway/Lambda no puede descargar PDF

Creé una función lambda utilizando SAM sin servidor y .NET core. Esta función se activa a través de API Gateway en una solicitud GET y debe devolver un archivo pdf. Estoy usando itextsharp para crear pdf e intento devolver el archivo pdf con el siguiente comando

 public async Task<IActionResult> GenerateReport() { var reportName = "test"; var result = await reportHandler.GenerateReportAsync(); return File(result, System.Net.Mime.MediaTypeNames.Application.Pdf, reportName + ".pdf"); }

Después de echar un vistazo a este hilo, AWS Lambda no devuelve el archivo PDF . También agrego application/pdf como tipo de medio binario en mi API Gateway como este en mi serverless.yaml

 Globals: Api: BinaryMediaTypes: - application~1pdf Resources: ApiGateway: Type: AWS::Serverless::Api Properties: StageName: Ref: Environment Name: Fn::Join: - "-" - - Ref: AWS::StackName - "api" ContentHandling: - CONVERT_TO_BINARY

Sin embargo, cuando trato de abrir el PDF, todavía recibo un error: "Error al abrir el documento PDF". Cuando abro el archivo pdf con el bloc de notas, se ve así (simplemente lo acorto)

 JVBERi0xLjQKJeLjz9MKMSAwIG9iago8PC9UeXBlL1hPYmplY3QvU3VidHlwZS9JbWFnZS9XaWR0aCAxNzIvSGVpZ2h0IDM2L0xlbmd0aCAxNjkwL0NvbG9yU3BhY2VbL0luZGV4ZWQvRGV2aWNlUkdCIDI1NSigoKBNTU0BAQGhoaECAgIXFxdMTEz9/f2Xl5f+/v7y8vJpaWkYGBjx8fHMzMxZWVkWFhalpaUcHBwZGRlLS0ukpKQGY1YzRlNjFhNjIwYjFkZjNjMDM1MjE1PjwwZTk1MTRhOGRmNWM0ZTYxYTYyMGIxZGYzYzAzNTIxNT5dPj4KJWlUZXh0LTUuNS4xMy4yCnN0YXJ0eHJlZgo0NTQzCiUlRU9GCg==

Cualquiera puede ayudar ¿cuál es el problema aquí?

Nota: funciona bien en mi máquina local (puedo abrir PDF perfectamente). Simplemente no funciona después de la implementación

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Usando sam 1.33.0, funcionó con un recurso AWS::Serverless::Api como este:

 LocalApi: Type: AWS::Serverless::Api Properties: StageName: dev DefinitionBody: x-amazon-apigateway-binary-media-types: - "*/*"
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!