             let filePath  = responseObject["filePath"] as? String
             let headers = responseObject["headers"] as? [String: String]
             var parameters = responseObject["parameters"] as? [String: AnyObject]
-            
+    
             if uploadUrl == nil {
                 return self.returnResult(command, "invalid url", false)
             }


@objc(FileTransferBackground) class FileTransferBackground : CDVPlugin {
    

    var operationQueue: OperationQueue {
        struct Static {
            static let queue: OperationQueue = OperationQueue()

            
            
            if !FileManager.default.fileExists(atPath: filePath!) {
                return self.returnResult(command, "file does not exists", false)
            }
            
            if parameters == nil {
                parameters = [:]
            }
    
            
            //check if server url exists before attempting any upload
            let checkForServerOperation = try HTTP.GET(uploadUrl!)
            checkForServerOperation.start { responseCheck in
                
                if let err = responseCheck.error {
                    print("error: \(err.localizedDescription)")
                    return self.returnResult(command, err.localizedDescription, false)
                }
                do {
                    //server is reachable, start upload
                    parameters!["file"] = Upload(fileUrl: URL(fileURLWithPath: filePath!))
                    let opt = try HTTP.POST(uploadUrl!, parameters: parameters, headers: headers)
                    
                    opt.onFinish = { response in
                        if let err = response.error {
                            print("error: \(err.localizedDescription)")
                            
                            return self.returnResult(command, err.localizedDescription, false)
                            
                        }
                        print("opt finished: \(response.description)")
                        
                        self.returnResult(command, "finished")
                        
                    }
                    
                    opt.progress = { progress in
                        
                        let pluginResult = CDVPluginResult(status:  CDVCommandStatus_OK, messageAs: ["progress" : progress*100])
                        pluginResult!.keepCallback = true
                        self.commandDelegate!.send(
                            pluginResult,
                            callbackId: command.callbackId
                        )
                        
                    }
                    /*
                     opt.start { response in
                     self.returnResult(command, response.text ?? "")
                     }
                     */
                    
                    self.operationQueue.addOperation(opt)
                    
                } catch let error {
                    print("got an error creating the request: \(error)")
                    self.returnResult(command, "http request could not be created", false)
                }
                
                
            }
            
            
            
        } catch let error {
            print("got an error creating the request: \(error)")
            self.returnResult(command, "http request could not be completed", false)
        }
        
    }
