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

163
Views
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
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!