Xcode Firebase在上传用户信息时出现错误Error Domain=com.google.HTTPStatus Code=403“(null)”

ckocjqey  于 2022-11-17  发布在  Go
关注(0)|答案(1)|浏览(84)

我正在xcode上制作一个简单的Firebase应用程序,用户需要上传他们的用户名、密码、电子邮件和个人资料图片。我本来一切都很好,但是当我添加代码上传他们的个人资料图片时,什么都没有用。这是我点击register时得到的错误:
2022-07-10 22:12:58.587723-0700 [13158:510029] GTMS会话提取器调用提取回调,数据{长度= 73,字节= 0x 7 b 0a 2020 22657272 6 f72223 a 207 b 0a 20... 2 e220 a20 207 d 0a 7 d},错误错误域=com.google.HTTPStatus Code=403“(null)”用户信息={数据={长度= 73,字节= 0x 7 b 0a 2020 22657272 6 f7223 a 207 b 0a 20... 2 e220 a20 207字符集=UTF-8}
下面是我的代码:

@objc func handleRegister() {
    guard let profileImage = profileImage else {
        self.errorLabel.text = "Please select a profile image"
        return
    }
    guard let email = emailTextField.text else {return}
    guard let password = passwordTextField.text else {return}
    guard let fullName = nameTextField.text else {return}
    guard let userName = usernameTextField.text else {return}
    
    guard let imageData = profileImage.jpegData(compressionQuality: 0.3) else { return }
    
    let filename = NSUUID().uuidString
    let storageRef = STORAGE_PROFILE_IMAGES.child(filename)
    
    storageRef.putData(imageData, metadata: nil) { meta, error in
        storageRef.downloadURL { url, error in
                guard let profileImageUrl = url?.absoluteString else { return }
            if let error = error {
                print(error)
                return
            }
                Auth.auth().createUser(withEmail: email, password: password) { result, error in
                    if let error = error {
                        print(error)
                        self.errorLabel.text =  "\(error.localizedDescription)"
                        return
                    }
                    
                guard let uid = result?.user.uid else { return }
                    
                let values = ["email": email,
                              "password": password,
                              "fullName": fullName,
                              "username": userName,
                              "profileImageUrl": profileImageUrl]
                    
                    print("DEGUG: Successfully registered user")
                    
                    REF_USERS.child(uid).updateChildValues(values) { error, ref in
                        print("DEBUG: Successfully updated user information")
                    }
                }
        }
        }
    }

在另一个Swift文件中,我有以下常量:

import Firebase

let DB_REF = Database.database().reference()

//User Reference
let REF_USERS = DB_REF.child("users")

//Images
let STORAGE_REF = Storage.storage().reference()
let STORAGE_PROFILE_IMAGES = STORAGE_REF.child("profile_images")

如果有人能给我指出正确的方向,我将不胜感激。

k2arahey

k2arahey1#

我把谷歌appspot网址在这里:

  1. let STORAGE_REF = Storage.storage().reference(forURL: "(Inser your url here")
    1.在我的Firebase中,在“存储”〉“规则”下,我将当前的规则更改为
rules_version = '2';

service firebase.storage {

  match /b/{bucket}/o {

    match /{allPaths=**} {

      allow read, write }}}

相关问题