@@ -1929,33 +1929,49 @@ angular.module('ngCordova.plugins.file', [])
1929
1929
return getAbsoluteFile ( filePath ) ;
1930
1930
} ,
1931
1931
1932
- downloadFile : function ( source , filePath , trustAllHosts , options ) {
1932
+ download : function ( source , filePath , options , trustAllHosts ) {
1933
1933
var q = $q . defer ( ) ;
1934
- var fileTransfer = new FileTransfer ( ) ;
1934
+ var ft = new FileTransfer ( ) ;
1935
1935
var uri = encodeURI ( source ) ;
1936
1936
1937
- fileTransfer . onprogress = q . notify ;
1938
- fileTransfer . download ( uri , filePath , q . resolve , q . reject , trustAllHosts , options ) ;
1937
+ if ( options && options . timeout !== undefined && options . timeout !== null ) {
1938
+ $timeout ( function ( ) {
1939
+ ft . abort ( ) ;
1940
+ } , options . timeout ) ;
1941
+ options . timeout = null ;
1942
+ }
1943
+
1944
+ ft . onprogress = function ( progress ) {
1945
+ q . notify ( progress ) ;
1946
+ } ;
1947
+
1948
+ ft . download ( uri , filePath , q . resolve , q . reject , trustAllHosts , options ) ;
1939
1949
return q . promise ;
1940
1950
} ,
1941
1951
1942
- uploadFile : function ( server , filePath , options ) {
1952
+ upload : function ( server , filePath , options , trustAllHosts ) {
1943
1953
var q = $q . defer ( ) ;
1944
- var fileTransfer = new FileTransfer ( ) ;
1954
+ var ft = new FileTransfer ( ) ;
1945
1955
var uri = encodeURI ( server ) ;
1946
1956
1947
- if ( options . timeout !== undefined && options . timeout !== null ) {
1957
+ if ( options && options . timeout !== undefined && options . timeout !== null ) {
1948
1958
$timeout ( function ( ) {
1949
- fileTransfer . abort ( ) ;
1959
+ ft . abort ( ) ;
1950
1960
} , options . timeout ) ;
1951
1961
options . timeout = null ;
1952
1962
}
1953
1963
1954
- fileTransfer . onprogress = q . notify ;
1955
- fileTransfer . upload ( filePath , uri , q . resolve , q . reject , options ) ;
1964
+ ft . onprogress = function ( progress ) {
1965
+ q . notify ( progress ) ;
1966
+ } ;
1967
+
1968
+ q . promise . abort = function ( ) {
1969
+ ft . abort ( ) ;
1970
+ } ;
1971
+
1972
+ ft . upload ( filePath , uri , q . resolve , q . reject , options , trustAllHosts ) ;
1956
1973
return q . promise ;
1957
1974
}
1958
-
1959
1975
} ;
1960
1976
1961
1977
/*
@@ -2060,51 +2076,93 @@ angular.module('ngCordova.plugins.fileOpener2', [])
2060
2076
. factory ( '$cordovaFileOpener2' , [ '$q' , function ( $q ) {
2061
2077
2062
2078
return {
2063
-
2064
- open : function ( file , type ) {
2065
-
2079
+ open : function ( file , type ) {
2066
2080
var q = $q . defer ( ) ;
2067
2081
cordova . plugins . fileOpener2 . open ( file , type , {
2068
- error : function ( e ) {
2082
+ error : function ( e ) {
2069
2083
q . reject ( e ) ;
2070
- } ,
2071
- success : function ( ) {
2084
+ } , success : function ( ) {
2072
2085
q . resolve ( ) ;
2073
2086
}
2074
2087
} ) ;
2075
2088
return q . promise ;
2076
-
2077
2089
} ,
2078
2090
2079
- uninstall : function ( pack ) {
2080
-
2091
+ uninstall : function ( pack ) {
2081
2092
var q = $q . defer ( ) ;
2082
2093
cordova . plugins . fileOpener2 . uninstall ( pack , {
2083
- error : function ( e ) {
2094
+ error : function ( e ) {
2084
2095
q . reject ( e ) ;
2085
- } ,
2086
- success : function ( ) {
2096
+ } , success : function ( ) {
2087
2097
q . resolve ( ) ;
2088
2098
}
2089
2099
} ) ;
2090
2100
return q . promise ;
2091
-
2092
2101
} ,
2093
2102
2094
- appIsInstalled : function ( pack ) {
2095
-
2103
+ appIsInstalled : function ( pack ) {
2096
2104
var q = $q . defer ( ) ;
2097
2105
cordova . plugins . fileOpener2 . appIsInstalled ( pack , {
2098
- success : function ( res ) {
2106
+ success : function ( res ) {
2099
2107
q . resolve ( res ) ;
2100
2108
}
2101
2109
} ) ;
2102
2110
return q . promise ;
2103
-
2104
2111
}
2105
-
2106
2112
} ;
2113
+ } ] ) ;
2114
+
2115
+ // install : cordova plugin add org.apache.cordova.file-transfer
2116
+ // link : https://github.com/apache/cordova-plugin-file-transfer/blob/master/doc/index.md
2117
+
2118
+ angular . module ( 'ngCordova.plugins.fileTransfer' , [ ] )
2119
+
2120
+ . factory ( '$cordovaFileTransfer' , [ '$q' , '$timeout' , function ( $q , $timeout ) {
2121
+ return {
2122
+ download : function ( source , filePath , options , trustAllHosts ) {
2123
+ var q = $q . defer ( ) ;
2124
+ var ft = new FileTransfer ( ) ;
2125
+ var uri = encodeURI ( source ) ;
2126
+
2127
+ if ( options && options . timeout !== undefined && options . timeout !== null ) {
2128
+ $timeout ( function ( ) {
2129
+ ft . abort ( ) ;
2130
+ } , options . timeout ) ;
2131
+ options . timeout = null ;
2132
+ }
2107
2133
2134
+ ft . onprogress = function ( progress ) {
2135
+ q . notify ( progress ) ;
2136
+ } ;
2137
+
2138
+ ft . download ( uri , filePath , q . resolve , q . reject , trustAllHosts , options ) ;
2139
+ return q . promise ;
2140
+ } ,
2141
+
2142
+ upload : function ( server , filePath , options , trustAllHosts ) {
2143
+ var q = $q . defer ( ) ;
2144
+ var ft = new FileTransfer ( ) ;
2145
+ var uri = encodeURI ( server ) ;
2146
+
2147
+ if ( options && options . timeout !== undefined && options . timeout !== null ) {
2148
+ $timeout ( function ( ) {
2149
+ ft . abort ( ) ;
2150
+ } , options . timeout ) ;
2151
+ options . timeout = null ;
2152
+ }
2153
+
2154
+ ft . onprogress = function ( progress ) {
2155
+ q . notify ( progress ) ;
2156
+ } ;
2157
+
2158
+ q . promise . abort = function ( ) {
2159
+ ft . abort ( ) ;
2160
+ } ;
2161
+
2162
+ ft . upload ( filePath , uri , q . resolve , q . reject , options , trustAllHosts ) ;
2163
+ return q . promise ;
2164
+ }
2165
+ } ;
2108
2166
} ] ) ;
2109
2167
2110
2168
// install : cordova plugin add https://github.com/EddyVerbruggen/Flashlight-PhoneGap-Plugin.git
@@ -3627,6 +3685,8 @@ angular.module('ngCordova.plugins', [
3627
3685
'ngCordova.plugins.facebook' ,
3628
3686
'ngCordova.plugins.facebookAds' ,
3629
3687
'ngCordova.plugins.file' ,
3688
+ 'ngCordova.plugins.fileTransfer' ,
3689
+ 'ngCordova.plugins.fileOpener2' ,
3630
3690
'ngCordova.plugins.flashlight' ,
3631
3691
'ngCordova.plugins.flurryAds' ,
3632
3692
'ngCordova.plugins.ga' ,
0 commit comments