I am creating a web app using mean stack where any user can upload an image and it would be stored in the mongo db or in a folder in the server system. I am using the angular-file-upload for uploading the image. The problem comes in the nodejs part where when i try to print the req.body it is showing an empty object.
HTMl code: <input type="file" ng-file-select="onFileSelect($files)" >
Angular code:
$scope.onFileSelect = function($files) {
for (var i = 0; i < $files.length; i++) {
var file = $files[i];
console.log(file);
$scope.upload = $upload.upload({
url: '/imagePost/'+Global.user._id,
method: 'POST' ,
data: {myObj: 'image'},
file: file,
}).progress(function(evt) {
console.log('percent: ' + parseInt(100.0 * evt.loaded / evt.total));
}).success(function(data, status, headers, config) {
console.log('success');
});
}
};
Node code:
app.post('/imagePost/:userid',function(req,res){
console.log('I came here');
console.log(req.body);
res.send('');
});
Here i just try to print the requestbody but i get an empty object. I included all the dependencies. If this doesnt work what I feel doing is reading the image and sending it in request and creating a new image in the node code which can be later stored in a folder. But why am I not getting any object in request body. Please help me..
req.body, it'll be inreq.files.app.use()).