@@ -316,6 +316,12 @@ export default function __identity(fileUploaderOptions, $rootScope, $http, $wind
316
316
*/
317
317
onCompleteItem ( item , response , status , headers ) {
318
318
}
319
+ /**
320
+ * Callback
321
+ * @param {FileItem } item
322
+ */
323
+ onTimeoutItem ( item ) {
324
+ }
319
325
/**
320
326
* Callback
321
327
*/
@@ -507,6 +513,15 @@ export default function __identity(fileUploaderOptions, $rootScope, $http, $wind
507
513
this . _onCompleteItem ( item , response , xhr . status , headers ) ;
508
514
} ;
509
515
516
+ xhr . timeout = item . timeout || 0 ;
517
+
518
+ xhr . ontimeout = ( e ) => {
519
+ var headers = this . _parseHeaders ( xhr . getAllResponseHeaders ( ) ) ;
520
+ var response = "Request Timeout." ;
521
+ this . _onTimeoutItem ( item ) ;
522
+ this . _onCompleteItem ( item , response , 408 , headers ) ;
523
+ } ;
524
+
510
525
xhr . open ( item . method , item . url , true ) ;
511
526
512
527
xhr . withCredentials = item . withCredentials ;
@@ -527,6 +542,10 @@ export default function __identity(fileUploaderOptions, $rootScope, $http, $wind
527
542
var iframe = element ( '<iframe name="iframeTransport' + Date . now ( ) + '">' ) ;
528
543
var input = item . _input ;
529
544
545
+ var timeout = 0 ;
546
+ var timer = null ;
547
+ var isTimedOut = false ;
548
+
530
549
if ( item . _form ) item . _form . replaceWith ( input ) ; // remove old form
531
550
item . _form = form ; // save link to new form
532
551
@@ -572,6 +591,15 @@ export default function __identity(fileUploaderOptions, $rootScope, $http, $wind
572
591
status = 500 ;
573
592
}
574
593
594
+ if ( timer ) {
595
+ clearTimeout ( timer ) ;
596
+ }
597
+ timer = null ;
598
+
599
+ if ( isTimedOut ) {
600
+ return false ; //throw 'Request Timeout'
601
+ }
602
+
575
603
var xhr = { response : html , status : status , dummy : true } ;
576
604
var headers = { } ;
577
605
var response = this . _transformResponse ( xhr . response , headers ) ;
@@ -595,6 +623,26 @@ export default function __identity(fileUploaderOptions, $rootScope, $http, $wind
595
623
input . after ( form ) ;
596
624
form . append ( input ) . append ( iframe ) ;
597
625
626
+ timeout = item . timeout || 0 ;
627
+ timer = null ;
628
+
629
+ if ( timeout ) {
630
+ timer = setTimeout ( ( ) => {
631
+ isTimedOut = true ;
632
+
633
+ item . isCancel = true ;
634
+ if ( item . isUploading ) {
635
+ iframe . unbind ( 'load' ) . prop ( 'src' , 'javascript:false;' ) ;
636
+ form . replaceWith ( input ) ;
637
+ }
638
+
639
+ var headers = { } ;
640
+ var response = "Request Timeout." ;
641
+ this . _onTimeoutItem ( item ) ;
642
+ this . _onCompleteItem ( item , response , 408 , headers ) ;
643
+ } , timeout ) ;
644
+ }
645
+
598
646
form [ 0 ] . submit ( ) ;
599
647
}
600
648
/**
@@ -704,6 +752,15 @@ export default function __identity(fileUploaderOptions, $rootScope, $http, $wind
704
752
this . progress = this . _getTotalProgress ( ) ;
705
753
this . _render ( ) ;
706
754
}
755
+ /**
756
+ * Inner callback
757
+ * @param {FileItem } item
758
+ * @private
759
+ */
760
+ _onTimeoutItem ( item ) {
761
+ item . _onTimeout ( ) ;
762
+ this . onTimeoutItem ( item ) ;
763
+ }
707
764
/**********************
708
765
* STATIC
709
766
**********************/
0 commit comments