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

166
Vistas
Using express-formidable to get multipart data , but it makes simple post requests with request body run forever

app.js

const express = require('express')
const app = express()

const app = express()
const PORT = process.env.SERVER_PORT || 8080

app.use(express.json())
app.use(express.urlencoded({
    extended : true
}))
app.use(formidableMiddleware());

app.listen(PORT, () => {
    console.log(`The application is up and running on ${PORT}`)
})

controller.js This contains the controller that takes base64 encoded image in formdata and that can be accessed with filename property (This is one controller which is working fine with formidable)

const uploadProfilePic = async (req, res) => {
    let strArr = req.fields.filename.split(',')
    let buffer = new Buffer(strArr[1], 'base64')
    let filename =
        Date.now().toString() + '' + strArr[0].split('/')[1].split(';')[0]
    try {
        req.user.profile = buffer
        req.user.filename = filename
        await req.user.save()
        return res.status(200).json(
        customMessage(true, {
            message: 'Successfully uploaded',
        }),
        )
    } catch (error) {
        return res.status(500).status(internalServerError)
    }
}

controller2.js This controller is not working properly, it does not even run when we use express-formidable and the post request route to which this controller is binded to, runs forever, but if we pass no request body then it runs perfectly or if we comment out:

//app.use(express-formidable);
//In app.js

then it runs properly but then controller.js doesnt run.

const updateUserData = async (req, res) => {
    try {
      const {_id, email, name, username, bio, code, platform, languages } = req.body
      if (username === undefined || code === undefined || !platform || !languages)
        return res
          .status(400)
          .json(customMessage(false, 'Please Satisy Validations'))
  
      let user = req.user
      let user1 = await UserModel.findById(_id)
      user1.username = username;
      user1.code = code;
      user1.bio = bio;
      user1.platform = platform;
      user1.languages = languages;
  
      if (!user) return res.status(500).json(internalServerError())
      else {
        await user1.save()
        console.log
        return res
          .status(200)
          .json(customMessage(true, `user with ${email} updated`))
      }
    } catch (error) {
      console.log(error)
      return res.status(500).json(internalServerError())
    }
}
over 4 years ago · Santiago Trujillo
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