【发布时间】:2018-05-26 06:12:08
【问题描述】:
我正在尝试创建一个将图像上传到 Firebase 存储并返回其路径的下载 url 的函数,以便我可以在应用程序的其他部分使用它。
这是函数的样子:
func uploadImage(to reference:StorageReference, image:UIImage) -> URL? {
let imageData = UIImageJPEGRepresentation(image, 0.2)
let metadata = StorageMetadata()
metadata.contentType = "image/jpeg"
var downloadURL = metadata.downloadURL()
reference.putData(imageData!, metadata: metadata) { (metadata, error) in
if error != nil {
print("Couldnt upload due to \(String(describing: error))")
}
downloadURL = metadata?.downloadURL()
}
return downloadURL!
}
我似乎无法得到我想要的结果,因为 downloadUrl 总是返回 nil。我究竟做错了什么?
【问题讨论】:
标签: swift firebase firebase-storage