Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

2.3K
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda