簡體   English   中英

FireBase存儲下載錯誤域= FIRStorageErrorDomain代碼= -13000

[英]FireBase Storage Download Error Domain=FIRStorageErrorDomain Code=-13000

我目前正在嘗試使用github上的Firebase存儲快速入門示例。 您只需在其中上傳圖像,然后在加載該視圖后將其下載到另一個視圖。 我可以將圖像上傳到存儲良好,但是當我嘗試下載圖像時會發生此錯誤。

錯誤域= FIRStorageErrorDomain代碼= -13000“發生未知錯誤,請檢查服務器響應。” UserInfo = {bucket = ****。appspot.com,> object = 379f921d-a0bb-44b5-b04e-f21cc7953848 / 485423329797 / IMG_0003.JPG,ResponseErrorDomain = NSCocoaErrorDomain,NSDestinationFilePath = / file:/ Users / mark **** ** /庫/開發人員/ CoreSim>模擬器/設備/ B600E8B9-95ED-4963-8282-9CDD43B7C25D / data /容器/數據/應用程序/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,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 = sPOSIXErrorDomain> No h文件或目錄“},ResponseErrorCode = 4}

我已經檢查了Firebase Storage方面的路徑,並且文件路徑正確,似乎無法檢索圖像。

下載圖像的代碼在下載文件的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]

}}

看起來這里的問題實際上是您的下載文件路徑不正確(引發的錯誤實際上是NSCocoaErrorDomain而不是網絡問題-看起來我們的錯誤消息過於特定於網絡)。

我看到的主要問題是您的文件路徑看起來像/file:/Users/...而我認為文件URL應該看起來像file:///Users/...

我通常會這樣創建本地文件:

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

您還可以使用NSHomeDirectoryForUser獲取用戶的基本目錄。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM