我使用了以下模块https://github.com/danialfarid/ng-file-upload,除了中止上传过程外,它已有详细记录。在上传文件期间,取消上传的代码无效。 我得到的错误是“中止不是一种功能”。我不知道如何应用abort()函数来取消上传过程。
我不知道我在这里想念的是什么,有谁可以给我一些关于为什么的想法?或任何建议。
我的HTML
<body ng-app="fileUpload" ng-controller="MyCtrl">
<h4>Upload on file select</h4>
<button ngf-select="uploadFiles($files)" multiple
accept="image/*,audio/*,video/*">Select Files</button>
<span class="progress" ng-show="progress >= 0">
<div style="width:{{progress}}%" ng-bind="progress + '%'"></div>
</span>
{{errorMsg}}
<button ng-click="cancelUpload()">Cancel</button>
</body>
JS(角)
var app = angular.module('fileUpload', ['ngFileUpload']);
app.controller('MyCtrl', ['$scope', 'Upload', '$timeout', function ($scope, Upload, $timeout) {
var upload = "";
$scope.uploadFiles = function (files) {
$scope.files = files;
if (files && files.length) {
upload = Upload.upload({
url: 'https://angular-file-upload-cors-srv.appspot.com/upload',
data: {
files: files
},
resumeSize: function() {return promise;}
}).then(function (response) {
$timeout(function () {
$scope.result = response.data;
});
}, function (response) {
if (response.status > 0) {
$scope.errorMsg = response.status + ': ' + response.data;
}
}, function (evt) {
$scope.progress =
Math.min(100, parseInt(100.0 * evt.loaded / evt.total));
});
}
};
$scope.cancelUpload = function(files){ // here is my cancel program
console.log("Cancelling");
upload.abort(); // this 'abort()' is not working as mentined
}