当我从手机上传图片时,应用程序崩溃,我收到错误
'FIRInvalidArgumentException',原因:'不支持的类型:NSURL(找到 在字段AccountTypeImageURL)'
这是我的函数,包含相关代码
func submitButtonADD(){
let imageName = NSUUID().uuidString
let storageRef = Storage.storage().reference().child("Account Type Images").child("\(imageName)png")
let sRef = Storage.storage().reference().child("Account Type Images").child("\(imageName)png")
guard let uid = Auth.auth().currentUser?.uid else { return }
if let uploadData = UIImagePNGRepresentation(self.profileImageView.image!) {
storageRef.putData(uploadData, metadata: nil, completion: { (metadata, error) in
if let error = error {
print(error)
return
}
sRef.downloadURL { url2, error in
if let error = error {
print(error)
} else {
// Get the download URL for 'images/stars.jpg'
let db = Firestore.firestore()
db.collection("Users").document(uid).setData(["AccountTypeImageURL": url2],merge: true)
}
}
})
}
}
答案 0 :(得分:3)
错误告诉您在尝试在NSURL
文档中保存Firestore
类型时,确实出现了什么问题。因此,将url转换为字符串,然后将其保存在Firestore中,如下所示:
db.collection("Users").document(uid).setData(["AccountTypeImageURL": url2.absoluteString],merge: true)