Firebase: provided bucket is not the same as 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:

Application terminated due to uncaught exception "NSInvalidArgumentException", reason: "Bucket supplied: slugbug -... appspot.com does not match storage stuff current instance: (null) '

Even if I use

let storageRef = FIRStorage().reference()

      

The bucket is zero.

Why?

+3


source to share


3 answers


I figured out the solution:

I changed the code:

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

      



in

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

      

... a very subtle but annoying bug

+2


source


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

+3


source


Use work with code below

 // 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
               }
     })

      

+2


source







All Articles