CopyPastor

Detecting plagiarism made easy.

Score: -1; Reported for: Open both answers

Possible Plagiarism

Plagiarized on 2018-02-17
by Arjun Patel

Original Post

Original - Posted on 2017-07-21
by Jack



            
Present in both answers; Present only in the new answer; Present only in the old answer;

Swift 4 with Alamofire 4 ================================= let isConnected = connectivity.isConnectedToInternet()
func updateProfile(firstName:String,lastName:String ,imageData:Data?,completion: @escaping (isValidUser)->()) { if self.isConnected { var parameters : [String:String] = [:] parameters["auth_key"] = loginUser?.authKey! parameters["User[first_name]"] = firstName parameters["User[last_name]"] = lastName let url = "\(baseUrl)\(basicAuthenticationUrl.updateProfile)" print(url) Alamofire.upload(multipartFormData: { (multipartFormData) in for (key, value) in parameters { multipartFormData.append("\(value)".data(using: String.Encoding.utf8)!, withName: key as String) } if let data = imageData { multipartFormData.append(data, withName: "image_url", fileName: "image.png", mimeType: "image/png") } }, usingThreshold: UInt64.init(), to: url, method: .post) { (result) in switch result{ case .success(let upload, _, _): upload.responseJSON { response in print("Succesfully uploaded = \(response)") if let err = response.error{ print(err) return } } case .failure(let error): print("Error in upload: \(error.localizedDescription)") } } }
}
As in Swift 3.x for upload image with parameter we can use below alamofire upload method-
static func uploadImageData(inputUrl:String,parameters:[String:Any],imageName: String,imageFile : UIImage,completion:@escaping(_:Any)->Void) { let imageData = UIImageJPEGRepresentation(imageFile , 0.5) Alamofire.upload(multipartFormData: { (multipartFormData) in multipartFormData.append(imageData!, withName: imageName, fileName: "swift_file\(arc4random_uniform(100)).jpeg", mimeType: "image/jpeg") for key in parameters.keys{ let name = String(key) if let val = parameters[name!] as? String{ multipartFormData.append(val.data(using: .utf8)!, withName: name!) } } }, to:inputUrl) { (result) in switch result { case .success(let upload, _, _): upload.uploadProgress(closure: { (Progress) in }) upload.responseJSON { response in if let JSON = response.result.value { completion(JSON) }else{ completion(nilValue) } } case .failure(let encodingError): completion(nilValue) } } }
> Note:-Additionally if our parameter is array of key-pairs then we can > use

var arrayOfKeyPairs = [[String:Any]]() let JSON = try? JSONSerialization.data(withJSONObject: arrayOfKeyPairs, options: [.prettyPrinted]) let jsonPrasatation = String(data: JSON!, encoding: .utf8)



        
Present in both answers; Present only in the new answer; Present only in the old answer;