1
votes

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[1]'

trying to make current user uploading his picture to storage it give me this error while testing

func userUpdatingInfo () {
    let storageRef = Storage.storage().reference()
    if let uploadData = self.userProfileImage.image?.pngData() {
        storageRef.putData(uploadData, metadata: nil) { (meta, error) in
            if (error != nil) {
                print(error ?? "Error in uploading Image")
                return
            } else {
                print(meta!)
            }
        }
    }
}
1

1 Answers

1
votes

You need to get a child reference, since you cannot directly save files into your firebase: https://firebase.google.com/docs/storage/ios/upload-files#create_a_reference

Have a reference in your storage by your user's id, I will update the answer assuming you have id property of users somewhere, you need to distinguish child references somehow

Try the updated code below:

func userUpdatingInfo () {
    let currentID = Auth.auth().currentUser?.uid
    let storageRef = Storage.storage().reference().child(currentID!)
    let uploadData = self.userProfileImage.image?.pngData()
    storageRef.putData(uploadData!, metadata: nil) { (meta, error) in
            if (error != nil) {
                print(error ?? "Error in uploading Image")
                return
            } else {
                print(meta!)
                return
            }
        }

}