简体   繁体   中英

Firebase: Provided bucket does not match the Storage bucket of the current instance in Swift

I have the following code:

let storageRef = FIRStorage().reference(forURL: "gs://slugbug-....appspot.com") // dots intentional
let imageRef = storageRef.child("testImage.jpg")

But the app crashes and I get the following message:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Provided bucket: slugbug-....appspot.com does not match the Storage bucket of the current instance: (null)'

Even if I use

let storageRef = FIRStorage().reference()

The bucket is nil.

Why?

You are missing .storage() .

Check your line. It should be:

let storageRef = FIRStorage.storage().reference(forURL: "gs://slugbug-....appspot.com") // dots intentional

Hope it helps

I figured out the solution:

I changed the code from:

let storageRef = FIRStorage().reference(forURL: "gs://slugbug-....appspot.com")

to:

let storageRef = FIRStorage.storage().reference(forURL: "gs://slugbug-....appspot.com")

... a very subtle but annoying bug

Use below code work

 // call storage ref from link
 self.storageRef =  FIRStorage.storage().reference(forURL: "your_URL")

     // Assuming your image size < 10MB.
     self.storageRef.data(withMaxSize: 10*1024*1024, completion: { (data, error) in
           if data != nil{ // if image found 
              let photo = UIImage(data: data!)
                  // User photo here
               }
     })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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