2014-11-08 3 views
1

노드 js가있는 웹 응용 프로그램을 개발 중입니다.정의되지 않은 'displayImage'속성을 읽을 수 없습니다.

router.post('/upload', function (req, res, next) { 
    fs.readFile(req.files.displayImage.path, function (err, data) { 
    var newPath = __dirname + "/uploads/uploadedFileName"; 
    fs.rename(newPath, 'filename', function (err) { 
     res.redirect('/'); 
    }); 
    }); 
}); 

그리고보기 :

Cannot read property 'displayImage' of undefined 

이미지의 게시물에 대한 내 코드는 다음과 같다 : 사진을 업로드하고 응용 프로그램의 파일 시스템에 저장하려고 할 때 나는 오류

form(action="upload", method="post", enctype="multipart/form-data") 
    input(type="file", name="displayImage") 
    input(type='submit') 

도움을 주셔서 감사합니다.

추신 : 나도 강력한 모듈이 사용되는 곳에서 자습서를 읽었습니다. 그것을 사용하는 것이 좋습니다 또는 내가 한 것처럼 충분하다?

답변

1

어떤 익스프레스 버전을 사용하고 있습니까? 멀티 파트 바디 용 익스프레스 4.0에서는 대안을 사용해야합니다. multer npm module

var multer = require('multer'); 

app.use(multer({dest: './uploads/'})); 

//app.post('/upload', function (req, res, next) { 
// console.log(req.files); 
//}); 
+1

multer를 사용

예를 들어, 당신이 구현할 수있는 업로드 파일은 잘 작동합니다 –

관련 문제