Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

558
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda