我目前正在尝试使用来自 github 的 firebase 存储的快速入门示例。您只需上传图像,然后在加载该视图后将其下载到另一个视图。我可以将图像上传到存储中,但是当我尝试下载图像时会发生此错误。
错误域=FIRStorageErrorDomain 代码=-13000 “发生未知错误,>请检查服务器响应。” UserInfo={bucket=****.appspot.com, >object=379f921d-a0bb-44b5-b04e-f21cc7953848/485423329797/IMG_0003.JPG, ResponseErrorDomain=NSCocoaErrorDomain, NSDestinationFilePath=/file:/Users/mark**** **/Library/Developer/CoreSim>ulator/Devices/B600E8B9-95ED-4963-8282-9CDD43B7C25D/data/Containers/Data/Application/8FFB7EB0-0AFD-4E10-AAB6-D7340F8E3DDB/Documents/myimage.jpg, NSLocalizedDescription=An发生未知错误,请检查服务器响应。, NSUserStringVariant=( Move ), NSSourceFilePathErrorKey=/Users/mark******/Library/Developer/CoreSimula>tor/Devices/B600E8B9-95ED-4963-8282->9CDD43B7C25D /data/Containers/Data/Application/8FFB7EB0-0AFD-4E10-AAB6->D7340F8E3DDB/tmp/CFNetworkDownload_5ZmlMp.tmp,
我已经检查了 Firebase 存储端的路径并且文件路径是正确的,它似乎无法检索图像。
下载图片的代码在下载文件的 viewdidload() 函数中
override func viewDidLoad() {
super.viewDidLoad()
storageRef = FIRStorage.storage().reference()
let paths = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory,
NSSearchPathDomainMask.UserDomainMask, true)
let documentsDirectory = paths[0]
let filePath = "file:\(documentsDirectory)/myimage.jpg"
let storagePath = NSUserDefaults.standardUserDefaults().objectForKey("storagePath") as! String
print("---------------")
print(filePath)
print("---------------")
print(storagePath)
// [START downloadimage]
storageRef.child(storagePath).writeToFile(NSURL.fileURLWithPath(filePath),
completion: { (url, error) in
if let error = error {
print("Error downloading:\(error)")
self.statusTextView.text = "Download Failed"
return
}
self.statusTextView.text = "Download Succeeded!"
self.imageView.image = UIImage.init(contentsOfFile: filePath)
})
// [END downloadimage]
} }