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

196
Views
FormData sends undefined file to backend although the value has been assigned?

this might seem like a trivial question, but I'm truly don't know what is wrong with my code. So, I've made this function that make a FormData, append it with name and value then sends it to the backend api:

const addGroup = () => {
  const token = Cookies.get("X-API-KEY");
  const formData = new FormData();
  formData.append("firstlead", "Is Me");
  formData.append("secondlead", "Is You");
  formData.append("name", "Our Group");
  axios
    .post(
      `http://localhost:7000/api/v1/groups`,formData,
      {
        headers: { authorization: token },
      }
    )
    .then(() => {
      notify();
    });
};

The backend api code is:

// API POST DATA GROUP (admin)
router.post('/',authAdminMiddleware, async (req, res) => {
const {
    firstlead,
    secondlead,
    name
} = req.body;
try {
    console.log(firstlead)
    console.log(secondlead)
    console.log(name)
} catch (error) {
    console.log(error);
    return res.status(500).json({code:500,status:false,message:'Server Error'});
}
})

I don't know why, but the backend console log said that all of my variables (firstlead, secondlead, and name) are undefined despite it's clearly has been assigned a value. I've tried using Postman, and it actually works, so my guess is there is something wrong with my append code on the frontend, but again, I don't know what it is. Any help will be appreciated!

Below is the console.log from the backend, it receive undefined despite the value of firstlead, secondlead, and name has been declared on the addGroup function.

Undefined from backend

about 4 years ago · Juan Pablo Isaza
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!