0

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?

Iñigo Beitia
  • 6,303
  • 4
  • 40
  • 46

1 Answers1

0

The problem was caused by changes in Express 4.0.

I solved it using Multer.

More info on this post: https://groups.google.com/forum/#!topic/express-js/INjdKyS3--0

Iñigo Beitia
  • 6,303
  • 4
  • 40
  • 46