Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
- if let image = info[.originalImage] as? UIImage {
- registrationViewModel.bindableImage.value = image
- let imageData = image.jpegData(compressionQuality: 0.5)
- Alamofire.upload(multipartFormData: { (multipartFormData) in
- multipartFormData.append(imageData!, withName: "account[user_attributes[profile_picture]]", fileName: "user_profile_picture.png", mimeType: "image/jpeg"); for(key, value) in self.parameters {
- multipartFormData.append(value.data(using: String.Encoding.utf8)!, withName: key)
- }
- }, to: URL_REGISTER,
- headers: nil)
- {(result) in
- switch result {
- case .success(let upload, _, _):
- upload.uploadProgress(closure: {(Progress) in
- print("Upload progress: (Progress.fractionCompleted)")
- })
- upload.responseJSON { response in
- if let JSON = response.result.value {
- print("JSON: (JSON)")
- }
- }
- case .failure(let encodingError):
- print(encodingError)
- }
- }
- } else {
- }
- dismiss(animated: true, completion: nil)
- }
- @objc fileprivate func handleRegister() {
- self.handleTapDismiss()
- guard let username = userNameTextField.text else {return}
- guard let email = emailTextField.text else {return}
- guard let password = passwordTextField.text else {return}
- registeringHUD.textLabel.text = "Register"
- registeringHUD.show(in: view)
- AuthService.instance.registerUser(email: email, password: password, username: username) { (success) in
- if success {
- print("user has signed up")
- // only upload images to backend once you are authorized
- } else {
- self.showHUDWithError()
- }
- self.dismiss(animated: true, completion: nil)
- }
- }
Add Comment
Please, Sign In to add comment