【发布时间】:2017-12-04 15:49:50
【问题描述】:
文件的多次上传适用于 angularjs,但我无法在我的 .then() 函数中获取文件名。
这是我的上传文件功能:
$scope.uploadFile = function(files,destinationPhp) {
$scope.montrerLoader = true;
for (var x=0;x<files.length;x++){
var fd = new FormData();
//Take the first selected file
fd.append("file", files[x]);
console.log(files[x].name);
var uploadUrl = destinationPhp;
$http.post(uploadUrl, fd, {
withCredentials: true,
headers: {'Content-Type': undefined },
transformRequest: angular.identity
}).then(function(data){
$scope.montrerLoader = false;
if(data.data.reponse=='ok'){
if(destinationPhp=='uploadFichier.php'){
Notification.success('Fichier transféré!');
$scope.rendezVous.fichiers.push({'nom':files[x].name});
}
}
else{
Notification.error(data.data.reponse);
}
});
}
};
效果很好,文件被上传到我的服务器目录,但问题是我需要这一行!:
$scope.rendezVous.fichiers.push({'nom':files[x].name});
我遇到了这个错误:
TypeError: files[x] is undefined
我已经尝试了很多方法,比如尝试将文件名放入 TEMP var 中,但它永远无法识别,或者最终总是推送相同的名称文件(这不合逻辑)。
您对上传到 $scope.rendezVous 后如何推送我的文件名有任何想法吗?
更糟糕的是这条线:
console.log(files[x].name);
在我的萤火虫控制台中显示权限文件名!!但是只要我尝试在里面使用.then(),那就不行了!
【问题讨论】:
标签: angularjs file-upload upload