Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am trying to get formdata from Angular to node service.
I have added below code.
But its not working.
Its giving
MulterError: Unexpected field
error.

What I have tried:

code : HTML

<form method="post" enctype="multipart/form-data">
  <div class="form-group">
    <input type="file" class="form-control" name="file" accept=".xlsx">
  </div>
 </form>


Angular Service call:

postReports(formdata : FormData){
   debugger;
   return this.http.post(this.baseURL, formdata);
 }


Node : controller

var express = require('express');
var router = express.Router();
var multer = require('multer');
var upload = multer();

var routes = function()
{
    router.route('/').post(upload.fields([]), function(req , res) {
        debugger;
        let formData = req.body;
        debugger;
        console.log(req);
        console.log(res);
    });

    return router;
};


Its giving error
500 (Internal Server Error) MulterError: Unexpected field


Can any one please help me..

Thanks...
Posted
Comments
Richard MacCutchan 16-Jan-19 9:50am    
Check the server logs for what field is unexpected.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900