Getting TypeError: Cannot read property ‘content-length’ of undefined When Using Node.js Formidable

“req” parameter in form.parse() method is omitted.

(method) IncomingForm.parse(req: IncomingMessage, callback?: (err: any, fields: Fields, files: Files) => any): void

Try changing the code as below.'/fileupload', function (req, res) {
    const form = new formidable.IncomingForm();
    form.parse(req, function (err, fields, files) {
        const oldpath = files.filetoupload.path;
        const newpath = 'C:/Users/Shubh Computer/Desktop/VSCode/Grades/1/' +;
        fs.rename(oldpath, newpath, function (err) {
            if (err) throw err; 
            res.write('File uploaded and moved!');

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top