【问题标题】:Firebase: Provided bucket does not match the Storage bucket of the current instance in SwiftFirebase:提供的存储桶与 Swift 中当前实例的存储存储桶不匹配
【发布时间】:2017-10-30 09:22:20
【问题描述】:
我有以下代码:
let storageRef = FIRStorage().reference(forURL: "gs://slugbug-....appspot.com") // dots intentional
let imageRef = storageRef.child("testImage.jpg")
但应用程序崩溃,我收到以下消息:
由于未捕获的异常而终止应用程序
'NSInvalidArgumentException',原因:'提供的存储桶:
slugbug-....appspot.com 的存储桶不匹配
当前实例:(null)'
即使我使用
let storageRef = FIRStorage().reference()
桶为零。
为什么?
【问题讨论】:
标签:
ios
swift
firebase
firebase-storage
【解决方案1】:
你错过了.storage()。
检查您的线路。应该是:
let storageRef = FIRStorage.storage().reference(forURL: "gs://slugbug-....appspot.com") // dots intentional
希望对你有帮助
【解决方案2】:
我想出了解决办法:
我将代码更改为:
let storageRef = FIRStorage().reference(forURL: "gs://slugbug-....appspot.com")
到:
let storageRef = FIRStorage.storage().reference(forURL: "gs://slugbug-....appspot.com")
...一个非常微妙但令人讨厌的错误
【解决方案3】:
使用下面的代码工作
// 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
}
})