【发布时间】:2018-05-14 14:22:01
【问题描述】:
更新我的 Firebase 项目后,我收到错误消息“StorageMetadata”类型的值没有成员“downloadURL”。在过去的几天里,我没有更改任何代码,并且随机它不再工作了。 相同的错误出现在 3 个不同的位置:
1:
// Referencing Firebase storage child with the unique identifier, and updating with the image from the picker
DatabaseManager.shared.REF_POSTS_IMAGES.child(imgUid).putData(imgData, metadata: metaData, completion: { (metadata, error) in
if error != nil {
print("Unable to upload image Firebase storage")
} else {
print("Successfully uploaded image to Firebase storage")
let downloadUrl = metadata?.downloadURL()?.absoluteString
if let url = downloadUrl {
//once the image is uploaded to firebase stoarge, its then posted to the database
self.postToFirebase(imgUrl: url)
}
}
})
2:
func uploadImages(_ data:Data,userid:String){
let metadata = StorageMetadata()
metadata.contentType = "image/jpeg"
let imagesRef = Storage.storage().reference().child("photoPosts")
let childs = imagesRef.child(userid)
var imgUrl = NSURL()
childs.putData(data, metadata: metadata) { (metadata, error) in
imgUrl = (metadata?.downloadURL())! as NSURL
self.updateURL(userid: userid, user_URL: imgUrl)
}
}
3:
func save() {
let newPostRef = Database.database().reference().child("posts").childByAutoId()
let newPostKey = newPostRef.key
// 1. save image
if let imageData = UIImageJPEGRepresentation(image, 0.5) {
let storage = Storage.storage().reference().child("images/\(newPostKey)")
storage.putData(imageData).observe(.success, handler: { (snapshot) in
self.downloadURL = snapshot.metadata?.downloadURL()?.absoluteString
let postDictionary = [
"imageDownloadURL" : self.downloadURL,
"caption" : self.caption
]
newPostRef.setValue(postDictionary)
})
}
}
其他帖子的答案对我没有帮助
【问题讨论】:
-
不,这篇文章对我没有帮助...
-
文档说它存在:firebase.google.com/docs/reference/swift/firebasestorage/api/… 但显然它在最新的 Firebase 版本中不存在。
-
找到这个firebase.google.com/support/release-notes/ios#5.0.0 在更改中指出“已删除 StorageMetadata 上的 downloadURLs 属性。使用 StorageReference.downloadURL(completion:) 获取当前下载 URL。”