Last active
November 28, 2016 05:33
-
-
Save makthrow/d68b23abd3389b69f782 to your computer and use it in GitHub Desktop.
saving and getting images in base64 string to Firebase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var data: NSData = NSData() | |
if let image = photoImageView.image { | |
data = UIImageJPEGRepresentation(image,0.1)! | |
} | |
let base64String = data.base64EncodedStringWithOptions(NSDataBase64EncodingOptions.Encoding64CharacterLineLength) | |
let user: NSDictionary = ["name":name!,"dob":dateOfBirthTimeInterval, "photoBase64":base64String] | |
//add firebase child node | |
let profile = firebase.ref.childByAppendingPath(name!) | |
// Write data to Firebase | |
profile.setValue(user) | |
ref.observeEventType(.Value, withBlock: { snapshot in | |
self.base64String = snapshot.value as String | |
let decodedData = NSData(base64EncodedString: base64String, options: NSDataBase64DecodingOptions.IgnoreUnknownCharacters) | |
if let decodedImage = UIImage(data: decodedData!) { | |
imageView.image = decodedImage | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment