我可以将图像上传到 Firebase 存储,但无法下载它们。这是我下载图像的代码:
let storage = FIRStorage.storage()
let localURL : NSURL! = NSURL(string: "file:///Documents/co.png")
// i also tried let localURL : NSURL! = NSURL.fileURLWithPath("file:///Documents/co.png")
func download() {
let storageRef = storage.referenceForURL("gs://project-5547819591027666607.appspot.com")
let imageRef = storageRef.child("co.png")
let downloadTask = imageRef.writeToFile(localURL) { (URL, error) -> Void in
if (error != nil) {
print(error?.localizedDescription)
}
else {
self.imageView.image = UIImage(data: data!)
}
}
}
我正在接收 - 可选(“发生未知错误,请检查服务器响应。”)
另外,一旦我下载了它们,我将如何查看该图像?
为了尝试查看图像是否已下载,我创建了一个 UIImageView 并在情节提要中为其设置了一个名为“imageView”的出口,然后将下载的图像设置为 UIImageView。
self.imageView.image = UIImage(data: data!)