I am using a library for AngularJS called angular-file-upload. Despite successfully setting it up and getting image uploads to work, I am facing an issue with passing the file to the server side (express js).
Jade:
input.form-input(ng-model="userAvatarFile" ng-file-select="onFileSelect($files)" name="userAvatarFile" type="file")
This is the AngularJS code snippet:
$scope.onFileSelect = function($files) {
console.log($files);
for (var i = 0; i < $files.length; i++) {
var file = $files[i];
$scope.upload = $upload.upload({
url: '/api/user/upload',
method: 'POST',
data: {myObj: $scope.userAvatarFile},
file: file,
}).progress(function(evt) {
console.log('percent: ' + parseInt(100.0 * evt.loaded / evt.total));
}).success(function(data, status, headers, config) {
console.log(data);
});
}
};
And here's the express code:
exports.upload = function(req, res) {
console.log(req.body);
console.log(req.files);
};
However, when checking the console output in express, it always shows:
{}
undefined
Any suggestions on what might be causing this issue?