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

583
Views
send file from nextjs API Routes

I use nextjs API Routes to connect to an external API

when I use a POST request to send a file, the file doesn't handled correctly in API Routes and I get 422 Unprocessable Entity Error

when I send only text it's OK, but when I add a file this error occur.

my request

const data = new FormData();
        data.append('first_name', firstName);
        data.append('last_name', lastName);
        data.append('phone_number', phoneNumber);
        image && data.append('avatar', image);

        axios.post(`${API_ROUTE}`, data, {
            headers: {
                'Content-Type': 'multipart/form-data'
            }
        })
        .then(res=>{
            alert(JSON.stringify(res.data, null, 2));
        })

my API Route

    const config = {
        headers: {
            'Content-Type': req.headers['content-type']
        }
    };

    axios.post(address, req.body, config)
    .then(r=>{
        res.statusCode = 200
        res.json( r.data )
    })
    .catch(err=>{
        res.json(err)
    })

in the request that API Route sending to the external API, there are some ? in the content of the file, but in the request that sending from browser to the API Route seems there are different characters

over 4 years ago · Santiago Trujillo
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!