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

225
Visualizações
Serverless API Gateway/Lambda fails to download PDF

I have created a lambda function using serverless SAM and .NET core. This function is fired via API Gateway on a GET request and should return a pdf file. I'm using itextsharp to create pdf and trying to return the pdf file with the following command

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

After take a look this thread AWS Lambda fails to return PDF file I also add application/pdf as binary mediatype in my API Gateway like this in my 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

However when I try to open the PDF, I still got an error: "failed to open PDF Document". When I open the pdf file with notepad it looks something like this (I just make it shortend)

JVBERi0xLjQKJeLjz9MKMSAwIG9iago8PC9UeXBlL1hPYmplY3QvU3VidHlwZS9JbWFnZS9XaWR0aCAxNzIvSGVpZ2h0IDM2L0xlbmd0aCAxNjkwL0NvbG9yU3BhY2VbL0luZGV4ZWQvRGV2aWNlUkdCIDI1NSigoKBNTU0BAQGhoaECAgIXFxdMTEz9/f2Xl5f+/v7y8vJpaWkYGBjx8fHMzMxZWVkWFhalpaUcHBwZGRlLS0ukpKQGY1YzRlNjFhNjIwYjFkZjNjMDM1MjE1PjwwZTk1MTRhOGRmNWM0ZTYxYTYyMGIxZGYzYzAzNTIxNT5dPj4KJWlUZXh0LTUuNS4xMy4yCnN0YXJ0eHJlZgo0NTQzCiUlRU9GCg==

Anyone can help what is the problem here?

Note: It working fine in my local machine (I can open PDF perfectly). It just doesn't work after deployment

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Using sam 1.33.0, It worked with an AWS::Serverless::Api resource like this:

  LocalApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: dev
      DefinitionBody:
        x-amazon-apigateway-binary-media-types:
          - "*/*"
over 4 years ago · Santiago Trujillo Relatório
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