Normally I would be able to find an answer to this question online but since its so new I have been having trouble.
When I have users sign into the app and they choose 4-5 pictures for their profile, how do I store those images in Firebase Storage and reference those images to that user in Firebase Database?
Thanks
You upload them to the Firebase Storage first and then store the url in Firebase Database
let storage = FIRStorage.storage()
let data: NSData = myImageData
let userProfilePic = storageRef.child("users/abc/profileimage.jpg")
let uploadTask = userProfilePic.putData(data, metadata: nil) { metadata, error in
if (error != nil) {
// Uh-oh, an error occurred!
} else {
let downloadURL = metadata!.downloadURL
// store downloadURL in db
storeUserProfileInDB(downloadURL)
}
}
func storeUserProfileInDB(profileImgUrl: NSURL) {
let ref = FIRDatabase.database().reference()
let key = ref.child("users").childByAutoId().key
let dictionaryUser = [ "userName" : name! ,
"imageUrl" : profileImgUrl.absoluteString,
]
let childUpdates = ["/users/\(key)": dictionaryTodo]
ref.updateChildValues(childUpdates, withCompletionBlock: { (error, ref) -> Void in
//save
})
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With