2016-01-21 62 views
0

我无法从角度取消上传文件请求,我使用下面提到的插件上传文件,根据作者感觉它是简单的方式,但我不确定我应该如何执行它。这是我如何上传文件,从Angular插件文件获取发布到PHP和PHP实习生读取整个文件,并通过卷曲流到Java API,所以,现在我有一个取消按钮,一旦用户点击取消上传按钮我需要能够停止从角插件上传,所以一旦上传停止,我可以再打一个电话来清理半流文件....和其他清理的东西。取消Angular文件上传

插件链接:https://github.com/danialfarid/ng-file-upload

$scope.uploadFiles = function(files) { 

if(files != undefined){ 
    $scope.currentFileUploadList = files; 
    $scope.$apply(); 
} 
angular.forEach(files, function(file, key) { 
    if(isSpecialChar(file.name)){ 
     //$scope.currentFileUploadList[key].status = false; 
     //$scope.$apply(); 
     file.upload = Upload.upload({ 
      url: $scope.BASE_FOLDER+'/sync/file/upload', 
      fields: {csrf_token: $('.csrf_token').html(), path: 'ParaBlu'}, 
      file: file 
     }); 

     file.upload.then(function (response) { 
      $timeout(function() { 
       file.result = response.data; 
       if(response.data.result == 'success'){ 
        $('.status').hide(); 
        toastr.success(response.data.file.fileName+' has been uploaded successfully', 'Successfully!!!', {allowHtml: true}); 
        $scope.currentFileUploadList.forEach(function(value, key){ 
         if(value.name.toString() == response.data.file.fileName.toString()){ 
          $scope.currentFileUploadList.splice(key, 1); 
         } 
        }); 
        if((files.length) == key){ 
         $('#uploadFiles').modal('hide'); 
        } 
       }else{ 
        toastr.error(file.name, response.data.msg, 'Fail!!!', {allowHtml: true}); 
       } 
      }); 
     }, function (response) { 
      if (response.status > 0) 
       $scope.errorMsg = response.status + ': ' + response.data; 
     }); 

     file.upload.progress(function (evt) { 
      file.progress = Math.min(100, parseInt(100.0 * 
       evt.loaded/evt.total)); 
     }); 
    }else{ 
     $scope.currentFileUploadList.forEach(function(value, key){ 
      if(value.name.toString() == file.name.toString()){ 
       $scope.currentFileUploadList.splice(key, 1); 
      } 
     }); 
     toastr.error('Special characters like (* \ | : " < > ? /) are not allowed, in a file name.', 'Fail!!!', {allowHtml: true}); 
    } 
}); 

};

+0

'/ *取消/中止正在进行的上传。 */ upload.abort(); /*' –

+0

从官方文档复制。一个按钮 - 一个回调,然后通过向后端发送请求来处理您需要为后端执行的任何操作。 –

+0

所以你应该这样工作,或者我应该为点击添加一个事件监听器,并调用upload.abort()函数。 –

回答

0

这不是与插件,而是与流的问题,我不得不取消上传,流程,不知道y的分开的php文件流?我虽然在php.ini中将用户中断设置为false,但也会停止php curl请求,一旦ajax请求被取消但它没有发生,无论如何感谢您的帮助。