angularjs – 角度文件上传队列
发布时间:2020-12-17 18:07:55 所属栏目:安全 来源:网络整理
导读:我正在使用此 Angular File Upload库进行上传过程. 它使用该repo上列出的相同设置完全上传. 但是,我必须将文件上传到队列中(一个接一个文件),而不是同时上传所有文件. Example. 例子是使用fork repo,要求是我使用我列出的那个. 还需要其他选项,如暂停/取消.
我正在使用此
Angular File Upload库进行上传过程.
它使用该repo上列出的相同设置完全上传. 但是,我必须将文件上传到队列中(一个接一个文件),而不是同时上传所有文件. Example. 例子是使用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); }); }; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |