简体   繁体   English

图片未上传到 Firebase 存储

[英]Image not uploading to Firebase Storage

While signing up on the app, the user is recorded into Firebase Authentication, but it's profile picture is not uploaded to Firebase Storage.在应用程序上注册时,用户被记录到 Firebase 身份验证中,但其头像没有上传到 Firebase 存储。 The code compiles fine too.代码也编译得很好。

private func persistImageToStorage() {
    
    guard let uid = Auth.auth().currentUser?.uid
    else { return }
    
    let ref = Storage.storage().reference(withPath: uid)
    
    guard let imageData = self.image?.jpegData(compressionQuality: 0.5) else { return }
    
    ref.putData(imageData, metadata: nil) { metadata, err in
        if let err = err {
            self.loginStatusMessage = "Couldn't upload your photo \(err)"
            return
        }
        
        ref.downloadURL { url, err in
            if let err = err {
                self.loginStatusMessage = "Error uploading your photo \(err)"
                return
            }
            
            self.loginStatusMessage = "Photo successfully uploaded!"
            print(url?.absoluteString)
        }
    }
}

Searched on related questions and none are getting this same error.搜索相关问题,没有人得到同样的错误。 Firebase is also updated to the latest version! Firebase也更新到最新版本了!

Since I forgot I had a @State var avatarImage = UIImage(systemName: "person.fill")!因为我忘记了我有一个@State var avatarImage = UIImage(systemName: "person.fill")! inside a struct of type View, it was taking the picture the user selected and doing nothing, because the code was taking another @State var as the picture with the info, to upload to Firebase (debugger showed self.image was throwing nil).在 View 类型的结构中,它正在拍摄用户选择的图片并且什么都不做,因为代码将另一个@State var作为带有信息的图片,上传到 Firebase(调试器显示self.image抛出 nil)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM