2014-04-22 91 views
0

我正在使用angular-file-upload將圖片上傳到運行Node和Express 4.0的服務器,並且我無法獲取有關文件數據的問題。角度文件上傳不會將文件添加到請求

下面是相關代碼:

<input type="file" ng-file-select="onFileSelect($files)"> 

角控制器:

$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代碼:

// Picture 
app.route('/api/settings/picture') 
    .post(middleware.auth, users.changePicture); 

路由處理:

exports.changePicture = function (req, res) { 
    var userId = req.user._id; 
    console.log(req.files); 
}; 

req.files總是undefined

任何想法,爲什麼這可能是?

回答

相關問題