Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

122
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda