@@ -525,6 +525,8 @@ export class FileUpload implements AfterViewInit, AfterContentInit, OnInit, OnDe
525525
526526 public uploadedFiles = [ ] ;
527527
528+ private fileUploadSubcription : Subscription ;
529+
528530 constructor (
529531 @Inject ( DOCUMENT ) private document : Document ,
530532 @Inject ( PLATFORM_ID ) private platformId : any ,
@@ -746,7 +748,10 @@ export class FileUpload implements AfterViewInit, AfterContentInit, OnInit, OnDe
746748 formData . append ( this . name ! , this . files [ i ] , this . files [ i ] . name ) ;
747749 }
748750
749- this . http
751+ // If the previous upload hasn't been finished, it is aborted.
752+ this . cancelUploadRequest ( ) ;
753+
754+ this . fileUploadSubcription = this . http
750755 . request ( < string > this . method , this . url as string , {
751756 body : formData ,
752757 headers : this . headers ,
@@ -805,6 +810,7 @@ export class FileUpload implements AfterViewInit, AfterContentInit, OnInit, OnDe
805810 clear ( ) {
806811 this . files = [ ] ;
807812 this . uploadedFileCount = 0 ;
813+ this . cancelUploadRequest ( ) ;
808814 this . onClear . emit ( ) ;
809815 this . clearInputElement ( ) ;
810816 this . cd . markForCheck ( ) ;
@@ -816,6 +822,7 @@ export class FileUpload implements AfterViewInit, AfterContentInit, OnInit, OnDe
816822 * @group Method
817823 */
818824 remove ( event : Event , index : number ) {
825+ this . cancelUploadRequest ( ) ;
819826 this . clearInputElement ( ) ;
820827 this . onRemove . emit ( { originalEvent : event , file : this . files [ index ] } ) ;
821828 this . files . splice ( index , 1 ) ;
@@ -826,12 +833,22 @@ export class FileUpload implements AfterViewInit, AfterContentInit, OnInit, OnDe
826833 * @param {Number } index - Index of the file to be removed.
827834 * @group Method
828835 */
829- removeUploadedFile ( index ) {
836+ removeUploadedFile ( index ) {
830837 let removedFile = this . uploadedFiles . splice ( index , 1 ) [ 0 ] ;
831838 this . uploadedFiles = [ ...this . uploadedFiles ] ;
832839 this . onRemoveUploadedFile . emit ( { file : removedFile , files : this . uploadedFiles } ) ;
833840 }
834841
842+ /**
843+ * Cancel upload file request.
844+ * */
845+ cancelUploadRequest ( ) {
846+ if ( this . fileUploadSubcription ) {
847+ this . fileUploadSubcription . unsubscribe ( ) ;
848+ this . fileUploadSubcription = undefined ;
849+ }
850+ }
851+
835852 isFileLimitExceeded ( ) {
836853 const isAutoMode = this . auto ;
837854 const totalFileCount = isAutoMode ? this . files . length : this . files . length + this . uploadedFileCount ;
0 commit comments