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

253
Views
FormData everything converting to string even arrays
const formData = new FormData()
formData.append('choices', [1, 2, 3])

choices converted to

'1,2,3'

And this is sent to node js which fails zod valdation because it is expecting array. this also same happens with numbers.

axios post request

axios.post('product', formData, {
      headers: {
        'Content-Type': 'multipart/form-data',
      },
    })
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

The value for formData will be converted to a string.

See documentation: https://developer.mozilla.org/en-US/docs/Web/API/FormData/append

The field's value. This can be a USVString or Blob (including subclasses such as File). If none of these are specified the value is converted to a string.

You can convert it back on the server side with:

const choicesArray = choices.split(',').map(Number);
about 4 years ago · Juan Pablo Isaza Report

0

 const numArray = [1, 2, 3, 4, 5];
    const formData = new FormData();
    formData.append("data", JSON.stringify(numArray));

Post request

 await axios.post(url, formData, {
      headers: {
        "Content-Type": "multipart/form-data",
        Accept: "application/json",
      },
    });
about 4 years ago · Juan Pablo Isaza 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!