无法将图像上传到Firebase存储-迅捷5

问题描述 投票:0回答:1

我无法将图像上传到Firebase存储中我在输出日志中发现此错误

“发生SSL错误,并且与服务器的安全连接无法制作。“

最后输出是

打印(“检查:4 >>不要放入图像”)

然后最少的代码不会执行,因此图像仍未上传

putData方法中,我也使用url参数,但也遇到了同样的问题

我的完整代码是

import UIKit
import FirebaseAuth
import FirebaseDatabase
import FirebaseStorage

class ViewController: UIViewController {

    @IBOutlet weak var imageview: UIImageView!
    @IBOutlet weak var emailTextView: UITextField!
    @IBOutlet weak var passwordTextView: UITextField!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }

    @IBAction func buttonAction(_ sender: Any) {

        Auth.auth().createUser(withEmail: emailTextView.text!, password: passwordTextView.text!){ (result, error) in
            if let _eror = error {
                print(_eror.localizedDescription)
                return
            }
            print("check: 1 >> After creating user\(result!)")


            let uid = result?.user.uid
            let storage = Storage.storage()
            let storageRef = storage.reference(forURL: "gs://porate-chai-4deee.appspot.com").child("profile_image").child(uid!)
            print("check: 2 >> \(storageRef)")


            if let profileImage = self.imageview!.image, let imageData = profileImage.jpegData(compressionQuality: 0.1) {
                print("check: 3 >> \(imageData)")
                storageRef.putData(imageData, metadata: nil) { (metadata, error) in
                    if error != nil {
                        print("check: 4 >> Don't put image")
                        return
                    }
                    print("put image on firebase storage")
                    storageRef.downloadURL(completion: {(url, error) in
                        if error != nil {
                            print(error!.localizedDescription)
                            return
                        }
                        let downloadURL = url?.absoluteString
                        print(downloadURL!)
                        let ref = Database.database().reference()
                        print("seeref\(ref)")
                        let userReference = ref.child("tutor")
                        let newUserReference = userReference.child(uid!)
                        newUserReference.setValue([
                            "email": self.emailTextView.text!,
                            "profileimageurl": downloadURL!
                        ])
                    })
                }
            }
        }
    }
}

我的Firebase存储规则为

rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write;
    }
  }
}

我也尝试使用此规则

rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write: if true;
    }
  }
}

enter image description here

ios firebase firebase-storage swift5
1个回答
0
投票

借助此答案"flutter pub get" can't get dependency plugins on Windows

[2020年3月27日之后,该代码仍然有效,但在2020年3月28日之后,孟加拉国的storage.googleapis.com出现了一些问题。

要解决此问题,请使用VPN工具并重新运行您的项目。我使用了Hotspot Sheild VPN,之后一切都很好。

我用这个热点盾:最快VPNwww.hotspotshield.com

然后再次上传文件

© www.soinside.com 2019 - 2024. All rights reserved.