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 !

2 Answers 2

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!

Sign up to request clarification or add additional context in comments.

Comments

-2

Try changing

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

to

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

2 Comments

how would changing the name of the file make a difference here?
Multer documentation suggest that the input type="file" name="value" in the upload tag and the upload.single('value') match !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.