I'm using angular-file-upload to upload a picture to the server running Node and Express 4.0 and I'm having trouble getting to the file data on the erver.
Here's the relevant code:
<input type="file" ng-file-select="onFileSelect($files)">
Angular controller:
$scope.onFileSelect = function ($files) {
var file = $files[0];
// [..] validation
$scope.upload = $upload.upload({
url: 'api/settings/picture',
method: 'POST',
file: file,
headers: {'Content-Type': undefined}
}).progress(function (evt) {
$scope.percent = parseInt(100.0 * evt.loaded / evt.total);
}).success(function (data) {
console.log(data);
}).error(function () {
console.log('error');
});
};
Server code:
// Picture
app.route('/api/settings/picture')
.post(middleware.auth, users.changePicture);
Route handler:
exports.changePicture = function (req, res) {
var userId = req.user._id;
console.log(req.files);
};
req.files
is always undefined
Any ideas why this could be?