I have got a fileUpload (made with NodeJS) and i want to show the success of the upload in the html in the {{upload.message}}. I implemented it with AngularJS but it didn't work. What am I doing wrong?
HTML
<form enctype="multipart/form-data" action="/upload"
method="POST">
<div class="form-group">
<input type="file" name="file" />
<p></p>
<input type="file" name="file" />
<p></p>
<input type="file" name="file" />
<br> <br>
<input type="submit" value="Upload File" name="submit"
class="btn btn-primary">
</form>
<span>{{upload.message}}</span>
</div>
NodeJS
router.post('/upload', function(req,res){
upload(req,res,function(err) {
var fileNames = [];
req.files.forEach(function(element){
fileNames.push(element.filename);
})
console.log('Selected Files: ', fileNames);
if(err){
res.end("Error: '" , err , "'");
}else{
res.sendStatus(204);
}
});
});
AngularJS
var self = this;
this.message = "";
this.upload= function(){
$http.post('/uploads')
.then(function success(result){
self.message = "Upload worked";
},
function error(response){
self.message = "Error upload failed";
});
};