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

556
Views
MulterError: Unexpected field using multer in Nodejs

I have a input field in angular

 <input type="file" id="input_id" name="ra_file" [(ngModel)]="UploadedFile"  hidden [disabled]="!isUploadAllowed">

and in node js I am trying to upload the file using multer.

    const express = require("express");
    const router = express.Router();
    var multer  = require('multer');
    var fs = require('fs');

    var upload = multer({ dest: 'files/upload_files/'});
    var type = upload.single('ra_file');
    router.post('/uploadDocument', type, function (req,res) {

        /** When using the "single"
            data come in "req.file" regardless of the attribute "name". **/
        var tmp_path = req.file.path;
      
        /** The original name of the uploaded file
            stored in the variable "originalname". **/
        var target_path = 'files/upload_files/' + req.file.originalname;
      
        /** A better way to copy the uploaded file. **/
        var src = fs.createReadStream(tmp_path);
        var dest = fs.createWriteStream(target_path);
        src.pipe(dest);
        src.on('end', function() { res.render('complete'); });
        src.on('error', function(err) { res.render('error'); });
      
      });

I am getting the error as

 MulterError: Unexpected field

When I console the request parameters . The req.file is as below

    {
      fieldname: 'slicedFile',
      originalname: 'load_testing_1.txt',
      encoding: '7bit',
      mimetype: 'text/plain',
      buffer: <Buffer 53 6f 75 72 63 65 53 63 68 65 6d 61 2c 43 6f 75 6e 74 72 79 4e 61 6d 65 2c 49 44 2c 41 4d 54 5f 45 58 43 4c 5f 54 41 58 2c 41 4d 54 5f 49 4e 43 4c 5f ... 340629006 more bytes>,
      size: 340629056
    }

And the req.body is as below

     {
      start: 'NA',
      end: 'NA',
      fileName: 'load_testing_1.txt',
      fileDesc: '',
      fileSize: '340629056',
      fileType: 'text/plain',
      fileId: '9ee941de-16e2-4998-80db-ded5aa8dc843',
      isLastBlob: 'true'
    }

Where did I made a mistake. Please help.

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!