@@ -123,13 +123,19 @@ public class SwiftFlutterUploaderPlugin: NSObject, FlutterPlugin {
123123 return
124124 }
125125
126+ guard let allowCellular = args [ " allowCellular " ] as? Bool else {
127+ result ( FlutterError ( code: " invalid_flag " , message: " allowCellular must be set " , details: nil ) )
128+ return
129+ }
130+
126131 uploadTaskWithURLWithCompletion (
127132 url: url,
128133 files: files,
129134 method: method,
130135 headers: headers,
131136 parameters: data,
132137 tag: tag,
138+ allowCellular: allowCellular,
133139 completion: { ( task, error) in
134140 if error != nil {
135141 result ( error!)
@@ -174,7 +180,12 @@ public class SwiftFlutterUploaderPlugin: NSObject, FlutterPlugin {
174180 return
175181 }
176182
177- binaryUploadTaskWithURLWithCompletion ( url: url, file: fileUrl, method: method, headers: headers, tag: tag, completion: { ( task, error) in
183+ guard let allowCellular = args [ " allowCellular " ] as? Bool else {
184+ result ( FlutterError ( code: " invalid_flag " , message: " allowCellular must be set " , details: nil ) )
185+ return
186+ }
187+
188+ binaryUploadTaskWithURLWithCompletion ( url: url, file: fileUrl, method: method, headers: headers, tag: tag, allowCellular: allowCellular, completion: { ( task, error) in
178189 if error != nil {
179190 result ( error!)
180191 } else if let uploadTask = task {
@@ -203,6 +214,7 @@ public class SwiftFlutterUploaderPlugin: NSObject, FlutterPlugin {
203214 method: String ,
204215 headers: [ String : Any ? ] ? ,
205216 tag: String ? ,
217+ allowCellular: Bool ,
206218 completion completionHandler: @escaping ( URLSessionUploadTask ? , FlutterError ? ) -> Void ) {
207219 let request = NSMutableURLRequest ( url: url)
208220 request. httpMethod = method
@@ -214,7 +226,7 @@ public class SwiftFlutterUploaderPlugin: NSObject, FlutterPlugin {
214226 }
215227 }
216228
217- completionHandler ( self . urlSessionUploader. enqueueUploadTask ( request as URLRequest , path: file. path) , nil )
229+ completionHandler ( self . urlSessionUploader. enqueueUploadTask ( request as URLRequest , path: file. path, wifiOnly : !allowCellular ) , nil )
218230 }
219231
220232 private func uploadTaskWithURLWithCompletion(
@@ -224,6 +236,7 @@ public class SwiftFlutterUploaderPlugin: NSObject, FlutterPlugin {
224236 headers: [ String : Any ? ] ? ,
225237 parameters data: [ String : Any ? ] ? ,
226238 tag: String ? ,
239+ allowCellular: Bool ,
227240 completion completionHandler: @escaping ( URLSessionUploadTask ? , FlutterError ? ) -> Void ) {
228241 var flutterError : FlutterError ?
229242 let fileManager = FileManager . default
@@ -290,7 +303,7 @@ public class SwiftFlutterUploaderPlugin: NSObject, FlutterPlugin {
290303 return
291304 }
292305
293- self . makeRequest ( path, url, method, headers, formData. contentType, formData. contentLength, completion: { ( task, error) in
306+ self . makeRequest ( path, url, method, headers, formData. contentType, formData. contentLength, allowCellular : allowCellular , completion: { ( task, error) in
294307 completionHandler ( task, error)
295308 } )
296309 }
@@ -302,6 +315,7 @@ public class SwiftFlutterUploaderPlugin: NSObject, FlutterPlugin {
302315 _ headers: [ String : Any ? ] ? = [ : ] ,
303316 _ contentType: String ,
304317 _ contentLength: UInt64 ,
318+ allowCellular: Bool ,
305319 completion completionHandler: ( URLSessionUploadTask ? , FlutterError ? ) -> Void ) {
306320 let request = NSMutableURLRequest ( url: url)
307321 request. httpMethod = method
@@ -324,7 +338,7 @@ public class SwiftFlutterUploaderPlugin: NSObject, FlutterPlugin {
324338 return
325339 }
326340
327- completionHandler ( urlSessionUploader. enqueueUploadTask ( request as URLRequest , path: path) , nil )
341+ completionHandler ( urlSessionUploader. enqueueUploadTask ( request as URLRequest , path: path, wifiOnly : !allowCellular ) , nil )
328342 }
329343}
330344
0 commit comments