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

2.3K
Views
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 answers
Answer question

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 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!