我正在使用此
Angular File Upload库进行上传过程.
它使用该repo上列出的相同设置完全上传.
但是,我必须将文件上传到队列中(一个接一个文件),而不是同时上传所有文件.
例子是使用fork repo,要求是我使用我列出的那个.
还需要其他选项,如暂停/取消.
目前的设置:
Controller: $scope.onFileSelect = function($files) { for (var i = 0; i < $files.length; i++) { //loop through files and put in an array } //execute upload function $scope.start(files); } } }; $scope.start = function(index) { $upload.upload({ //upload clode }).progress(function(evt) { //Progress calculation }).success(function(data,status,headers,config) { //Success return }).error(function(data,config) { console.log(data); }); };
解决方法
试试这个,基本上它只是一次发送一个文件,直到完成.如果您希望在发送每个文件之间有延迟,可以使用$timeout:
$scope.onFileSelect = function($files) { $scope.uploadList = $files; $scope.uploadIndex = 0; $scope.start(uploadIndex) }; $scope.start = function() { $upload.upload({ //upload code,send file // Send file $scope.uploadList[$scope.uploadIndex]; }).progress(function(evt) { //Progress calculation }).success(function(data,config) { //Success return $scope.uploadIndex++; // Send the next file by calling ourselves if (uploadIndex < uploadList.length) $scope.start(); // Send the next one now - could be deferred a little by using $timeout }).error(function(data,config) { console.log(data); }); };