0

I want to upload a file in a node js + angular js application I defined a directive and a service in my controller like said here Data not posting in multipart form data in angular and node js(File uploading with angular and node js) It seems like it's not workig since my server is returning 500 internal error

my js file

var express = require('express');
var router = express.Router();
var multer = require('multer');
var upload = multer({ dest: __dirname+'/../../uploads' });
router.post('/fileUpload',upload.single('myFile'),uploadFile);
function uploadFile(req,res,next) {

console.log(req.file); //returning undefined 
  }

In addition a directory 'uploads' is created but nothing is added to it and when I inspect the browser I find internal server error 500

Any help would be appreciated !

Community
  • 1
  • 1
Farah gdoura
  • 71
  • 1
  • 4

2 Answers2

0

Actually I found a post that solved my problem perfectly since I was dealing with multer, angular js and node js nodejs + multer + angularjs for uploading without redirecting This is helpful!

Community
  • 1
  • 1
Farah gdoura
  • 71
  • 1
  • 4
-2

Try changing

router.post('/fileUpload',upload.single('myFile'),uploadFile);

to

router.post('/fileUpload',upload.single('file'),uploadFile);
Sreeragh A R
  • 2,871
  • 3
  • 27
  • 54