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

273
Views
Axios - Node.js - localhost server receive a req.body of null when upload a file with axios

I build a local server by Nodejs. All I want is to upload a file from my website. When I send a post request by axios from the website, my localhost just receive a req.body of a null object({}). I have no idea about it. Here's the code. the font end:

        let fileList = this.$refs.getPic.files
        let file = fileList[0]
        let fileReader = new FileReader()
        fileReader.readAsDataURL(file)      
        fileReader.addEventListener('load', () => {
            let res = fileReader.result
            this.picURL = res
        })
        const formData = new FormData()
        formData.append('userPicture', file)
        let config = {
            headers: {
                'Content-Type': 'multipart/form-data',
            },
        }
        axios.post('http://127.0.0.1:4000/data/account/file', {formData}, config)
        .then(res => {
            console.log(res)
        })
        .catch(err => {
            console.log(err)
        })

the server:

router.post('/account/file', (req, res) => {
    console.log(req.body)        // here i get a {}
    console.log(req.headers)
    res.send(req.body)
})
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You have to use a middleware like multer to handle this easily.

Check multer on npm

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