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});
}
});
};
'/ *取消/中止正在進行的上傳。 */ upload.abort(); /*' –
從官方文檔複製。一個按鈕 - 一個回調,然後通過向後端發送請求來處理您需要爲後端執行的任何操作。 –
所以你應該這樣工作,或者我應該爲點擊添加一個事件監聽器,並調用upload.abort()函數。 –