[英]angular-file-upload not adding file to the request
我正在使用angular-file-upload將圖片上傳到運行Node and 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');
});
};
服務器代碼:
// 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
任何想法為什么會這樣?
該問題是由Express 4.0中的更改引起的。
我用Multer解決了。
有關此帖子的更多信息: https : //groups.google.com/forum/#!topic/express-js/INjdKyS3--0
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.