我试图下载一个网址存储在我的数据库中,但Firebase中的新更新禁止我这样做,要求我使用新的方式下载网址。这是我的代码:
let imageName = NSUUID().uuidString
let storageRef = storage.reference().child("project_images").child("\(imageName)")
guard let uplodaData = UIImageJPEGRepresentation(image, 1) else {
return
}
let uploadTask = storageRef.putData(uplodaData, metadata: nil, completion: { (metadata, error) in
if error != nil{
print(error ?? "Failed to upload data in the uploadImages object there was an error:", error!)
return
}
如果我在此处设置断点,它不会继续经过下一节,我不知道为什么。当存储在错误的节点或其他东西时,我通常会看到这些问题。
metadata?.storageReference?.downloadURL(completion: { (url, error) in
if error != nil {
print("Failed to download url:", error!)
return
}
let url = "\(String(describing: url))"
uploadedImageUrlsArray.append(url)
uploadCount += 1
if uploadCount == imagesCount{
completionHandler(uploadedImageUrlsArray)
}
})
})
当我只是一个断点时,我可以检查完成中的错误变量,它没有。
有人可以告诉我这里我做错了什么。
答案 0 :(得分:1)
您为此特定图片创建了存储参考,因此请使用该参考而不是metadata?.storageReference
。
storageRef.downloadURL(completion: { (url, error) in
if error != nil {
print("Failed to download url:", error!)
return
}
let url = "\(String(describing: url))"
uploadedImageUrlsArray.append(url)
uploadCount += 1
if uploadCount == imagesCount{
completionHandler(uploadedImageUrlsArray)
}
})
})