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

118
Views
Form Data doesn't save the image correctly

I'm trying to save Form Data with its information but when I do so I get a weird looking object that I think the server is refusing to accept and returns a 500 error.

Here is how I'm handling it:

const formData = new FormData();
let currentlyUploaded = e.target.files[0];
formData.append(currentlyUploaded.name, currentlyUploaded);
// passing the data in function then ...

And this is how it looks when I console it later before the call, and it doesn't look correct. console log

here is the route:

router.post(
  `${prefix}/create-quiz`,
  userAuth,
  upload.single("file"),
  async (req, res) => {
    try {
      const user = await User.findOne({ _id: req.params.userId });

      const newQuiz = new Quiz({
        purchaseCoins: req.body.purchaseCoins,
        privacy: req.body.privacy,
        created_by: req.params.userId,
        category: req.body.category,
        title: req.body.title,
        description: req.body.description,
        difficulty: req.body.difficulty,
        questions: req.body.questions,
        thumbnail: req.file.filename,
      });

      await newQuiz.save();
      user.quizzes.push(newQuiz._id);
      await user.save();

      return res.status(201).json({
        message: "Finally , quiz created properly!",
        success: true,
      });
    } catch (error) {
      // return res.status(500).json({
      //   message: "Can't save this quiz try again, check if it already exists",
      //   success: false,
      // });
      console.log("errorium: ", error)
    }
  }
);
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!