简体   繁体   English

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

[英]Unable to upload image into Firebase Storage - swift 5

I can't upload an image into Firebase Storage I found this error in my output log我无法将图像上传到 Firebase Storage 我在输出日志中发现了这个错误

"An SSL error has occurred and a secure connection to the server cannot be made." “发生 SSL 错误,无法与服务器建立安全连接。”

and last output is最后输出是

print("check: 4 >> Don't put image")打印(“检查:4 >>不要放图像”)

Then the least of the code doesn't execute therefore the image still not uploading那么最少的代码不会执行,因此图像仍未上传

In the putData method i also use url parameter but also got the same problemputData 方法中,我也使用了url 参数,但也遇到了同样的问题

MY Full code is我的完整代码是

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

My Firebase Storage Rules is我的 Firebase 存储规则是

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

I also try this rules我也试试这个规则

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

在此处输入图片说明

With the help of this answer "flutter pub get" can't get dependency plugins on Windows借助此答案“flutter pub get”无法在 Windows 上获取依赖项插件

After 27-03-2020 the code still work but after 28-03-2020 have some problem storage.googleapis.com in Bangladesh.在 27-03-2020 之后代码仍然有效,但在 28-03-2020 之后在孟加拉国的 storage.googleapis.com 出现了一些问题。

To overcome this issue, use VPN tool and re-run your project.要解决此问题,请使用 VPN 工具并重新运行您的项目。 I used Hotspot Sheild VPN and after that everything was good.我使用了 Hotspot Sheild VPN,之后一切都很好。

I use this Hotspot Shield: Fastest VPNwww.hotspotshield.com我使用这个 Hotspot Shield: Fastest VPNwww.hotspotshield.com

Then the file again uplod然后文件再次上传

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

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