Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

554
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda