【问题标题】:FireBase Storage Download Error Domain=FIRStorageErrorDomain Code=-13000FireBase 存储下载错误域=FIRStorageErrorDomain 代码=-13000
【发布时间】:2016-09-17 09:41:18
【问题描述】:

我目前正在尝试使用来自 github 的 firebase 存储的快速入门示例。您只需上传图像,然后在加载该视图后将其下载到另一个视图。我可以将图像上传到存储中,但是当我尝试下载图像时会发生此错误。

Error Domain=FIRStorageErrorDomain Code=-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=( 移动 ), 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, NSFilePath=/Users/mark******/Library/Developer/CoreSimulator/Devices/B6>00E8B9-95ED-4963-8282->9CDD43B7C25D/data/Containers/Data /Application/8FFB7EB0-0AFD-4E10-AAB6->D7340F8E3DDB/tmp/CFNetworkDownload_5ZmlMp.tmp, NSUnderlyingError=0x7f8036a682d0 {Error Domain=NSPOSIXErrorDomain Code=2 >"No such file or directory"}, ResponseErrorCode=4}

我检查了 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]

} }

【问题讨论】:

    标签: ios swift firebase firebase-storage


    【解决方案1】:

    看起来这里的问题实际上是您的下载文件路径不正确(引发的错误实际上是 NSCocoaErrorDomain 而不是网络问题 - 看起来我们的错误消息过于特定于网络)。

    我看到的主要问题是您的文件路径看起来像 /file:/Users/...,而我认为文件 URL 应该看起来像 file:///Users/...

    我通常像这样创建本地文件:

    NSURL *tmpDirURL = [NSURL fileURLWithPath:NSTemporaryDirectory()];
    NSURL *fileURL = [[tmpDirURL URLByAppendingPathComponent:@"hello"] URLByAppendingPathExtension:@"txt"];
    

    您也可以使用NSHomeDirectoryForUser 来获取用户的基本目录。

    【讨论】:

      猜你喜欢
      • 2016-11-17
      • 2021-12-30
      • 2016-09-16
      • 2017-07-03
      • 1970-01-01
      • 2018-11-01
      • 2018-10-11
      • 2020-06-15
      • 2022-07-01
      相关资源
      最近更新 更多