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

2.3K
Visualizações
Receive and send multipart/form-data file in AWS Lambda

I'm trying to do a multipart/form-data POST containing a pdf file to an AWS lambda function, do a few checks on the file and then POST the file to an external API.

I'm using the serverless framework with node.js and the aws-lambda-multipart-parser plugin to receive the file.

The file upload from the client to lambda works, and I can print the buffer content to the console. The part that does not work is the forwarding of the file to an external API.

This is my current axios setup to make a POST request to the external API:

const formData = new FormData();
formData.append("file", file.content, file.filename);

const res = await axios.post(`https://external-api.com`, formData, {
  headers: { ...formData.getHeaders(), "Access-Control-Allow-Origin": "*" },
  params: {
    someParams: foo
  }
});

file.content actually contains a Buffer with the file content, but when I make the request, the external API returns an error and the request fails...

Interestingly, the whole setup works when I run the serverless function locally with sls offline. That may suggest that there is a problem with the API Gateway setup.

Some additional info:

Based on the instructions from the multipart plugin I added the binary data type in the API Gateway settings:

enter image description here

This is the config of the endpoint in AWS Gateway:

enter image description here

I also tried this SO question and the AWS documentation, but they only cover how to receive a binary file, not how to send one.

Is it possible to receive and then send a file in lambda, or should this be solved in a different way?

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

0

I had the same problem with that library. So I tried with - https://www.npmjs.com/package/aws-multipart-parser - there is also a description of what to write in serverless.yml file. It is working like charm now!

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