gpt4 book ai didi

ios - 将当前用户的图像上传到 Firebase

转载 作者:行者123 更新时间:2023-11-28 05:47:54 25 4
gpt4 key购买 nike

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

试图让当前用户上传他的图片到存储它在测试时给我这个错误

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!)
}
}
}
}

最佳答案

您需要获取子引用,因为您不能直接将文件保存到您的 firebase 中:https://firebase.google.com/docs/storage/ios/upload-files#create_a_reference

通过你的用户 ID 在你的存储中有一个引用,假设你在某处有用户的 id 属性,我将更新答案,你需要以某种方式区分子引用

尝试下面更新的代码:

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
}
}

}

关于ios - 将当前用户的图像上传到 Firebase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53986935/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com