我无法从角度取消上传文件请求,我使用下面提到的插件上传文件,根据作者的说法感觉它很简单,但我不知道应该如何实现它。这是我上传文件的方式,从Angular插件文件发布到php和php实习生读取整个文件并通过curl将其流式传输到java api,所以,现在我有一个Cancel按钮,一旦用户点击该取消上传按钮我需要能够停止从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 :(得分:0)
这个插件没有问题而不是流媒体,我不得不单独取消php文件流来取消上传,进程,不确定y?我虽然在php.ini中将用户中断设置为false会在ajax请求被取消后停止php curl请求但是没有发生,无论如何感谢你的帮助。