通常情况下,我可以在网上找到这个问题的答案,但由于它是如此新,我一直有麻烦。当我让用户登录应用程序并选择4-5张图片作为其个人资料时,我如何将这些图片存储在Firebase Storage中并在Firebase Database中将这些图片引用给该用户?谢谢
ifsvaxew1#
您首先将它们上传到Firebase Storage,然后将URL存储在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 }) }
1条答案
按热度按时间ifsvaxew1#
您首先将它们上传到Firebase Storage,然后将URL存储在Firebase Database中