-1
我在上傳文件時遇到問題。我有一個表單將數據發送到我的路由器文件中的控制器。當數據發佈時,請求文件未發現。我試圖做的是將圖像發送給我的公衆/圖像,然後將圖像名稱放入我的候選人中。嘗試發佈表單信息時,請求文件未定義
這裏是我的形式
<div class="page-wrap text-center">
<div ng-controller = "candidatesController">
<div class = "row">
<div class=" col-md-6 col-md-offset-3">
<form class = "content-margin" ng-submit="addCandidate()" style="margin-top:30px" enctype = "multipart/form-data">
<h3 class = "formheading"> Add a new Candidate</h3>
<div class = "form-group" align = "center">
<input type = "string" class = "form-control" placeholder = "candidate name" ng-model = "formData.name" ng-style = "{'width':150 + 'px'}"></input>
</div>
<div class = "form-group" align = "center">
<input type = "string" class = "form-control" placeholder = "candidate role" ng-model = "formData.role" ng-style = "{'width':150 + 'px'}"></input>
</div>
<div class = "form-group" align = "center">
<input type = "string" class = "form-control" placeholder = "candidate email" ng-model = "formData.email" ng-style = "{'width':150 + 'px'}"></input>
</div>
<input method = "post" type="file" name="userPhoto" nd-model = "file"/>
<button type="submit" class="btn btn-primary">Add Candidate</button>
</form>
</div>
</div>
</div>
</div>
,這裏是我的控制器
router.addPerson = function(req, res) {
console.warn(req.files);
var candidate = new CandidateModel();
candidate.name = req.body.name;
console.warn(req.body.name);
candidate.role = req.body.role;
console.warn(req.body.role);
candidate.email = req.body.email;
console.warn(req.body.email);
console.warn(candidateImage);
// Save the donation and check for errors
candidate.save(function(err) {
if (err)
res.send(err);
res.json({ message: 'Donation Added!', data: candidate });
});
}
我沒有文件上傳代碼沒有完成,因爲我不能甚至可以被髮送過來的文件。這是我的控制器中的功能。
$scope.updateCandidate = function(){
$scope.formData.id = candidateId.getID();
$http.post('/candidates/'+ candidateId.getID(), $scope.formData)
.success(function(data){
console.log(data);
$scope.candidates = data;
$location.path('/candidates');
})
.error(function(data){
console.log('Error:' + data);
});
}
任何幫助將是巨大的
發送請求? Multer,公務員?也許是自定義的? – peteb
我正在使用Mulder – ToljinSaturn