Skip to content

Instantly share code, notes, and snippets.

@amrangry
Created November 13, 2017 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amrangry/d17ea152060246d17a5b4c76bd091d78 to your computer and use it in GitHub Desktop.
Save amrangry/d17ea152060246d17a5b4c76bd091d78 to your computer and use it in GitHub Desktop.
class func editProfile(name:String , email:String , mobile:String , city_id : Int , password:String , passwordConfirmation:String , logo : UIImage , completionHandler :@escaping (_ isSuccess:Bool , _ message:String , _ user : User?)->Void){
guard let user = User.currentUser().user else {
return
}
let parameters : Parameters = [
"email" : email , "password" : password , "name" : name , "password_confirmation" : passwordConfirmation , "mobile" : mobile , "city_id" : "\(city_id)"
]
let imgData = UIImageJPEGRepresentation(logo, 0.5)!
let stringURl = "\(baseURL)\(URLs.profile.rawValue)?api_token=\(user.api_token!)"
Alamofire.upload(multipartFormData: { multipartFormData in
multipartFormData.append(imgData, withName: "logo",fileName: "file.jpg", mimeType: "image/jpg")
for (key, value) in parameters {
multipartFormData.append((value as AnyObject).data(using: String.Encoding.utf8.rawValue)!, withName: key)
}
},
to:stringURl)
{ (result) in
switch result {
case .success(let upload, _, _):
upload.uploadProgress(closure: { (progress) in
print("Upload Progress: \(progress.fractionCompleted)")
})
upload.responseJSON
{ response in
//print response.result
print(response.result.value)
//TODO parse data again // cach user with the new image data to be openned again when he comes
}
case .failure(let encodingError):
print(encodingError)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment