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

450
Views
How can upload file with method PUT ? [Node JS]

I use library "method-override" on my form

<form method="post"  action="/book/{{book._id}}/update?_method=PUT" class="">
...
</form/>

and I cannot upload file with method [PUT]

this is my multer:

const multer = require('multer');

const storage = multer.diskStorage({
  destination(req, file, cb) {
    cb(null, './public/images/');
  },
  filename(req, file, cb) {
    const uniqueSuffix = `${Date.now()}-${Math.round(Math.random() * 1E9)}`;
    cb(null, `${file.fieldname}-${uniqueSuffix}-${file.originalname}`);
  },
});

module.exports = multer({ storage });

this is my router:

const bookController = require('../app/controllers/BookController');
const upload = require('../middle/uploadImage');
    router.post('/stored', upload.single('image'), bookController.stored); // create
    router.put('/:id/update', upload.single('image'), bookController.update);// update

and my controler:

  // [PUT] / book/:id/edit
  // eslint-disable-next-line class-methods-use-this
  async update(req, res, next) {
    let { file, body } = req;
    let image;
    console.log(file); // undefined
    if (file) {
      image = await uploadFile(file.path, file.filename);
    }
    body = { ...body, image };
    Book.updateOne({ _id: req.params.id }, body)
      .then(() => {
        res.redirect('/stored/books');
      })
      .catch((err) => next(err));
  }

and I cannot get file from controller

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!