简体   繁体   中英

Couldn't upload file using multer in node js + angular js application

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 !

实际上,我发现一个帖子可以完美解决我的问题,因为我正在处理multer,angular js和node js nodejs + multer + angularjs,无需重定向即可上传,这很有帮助!

Try changing

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

to

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM