简体   繁体   中英

angular-file-upload not adding file to the request

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM