简体   繁体   中英

FireBase Storage Download Error Domain=FIRStorageErrorDomain Code=-13000

I'm Currently trying to use the quick start examples for firebase storage from github. Where you simply upload an image and then download it to a another view once that view is loaded. I can upload images to storage fine but when I try to download the images this error occurs.

Error Domain=FIRStorageErrorDomain Code=-13000 "An unknown error occurred, >please check the server response." 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 unknown error occurred, please check the server response., 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=NSPOSIXErrorDomain Code=2 >"No suc h file or directory"}, ResponseErrorCode=4}

I've checked the paths on the Firebase Storage side of things and the file paths are correct, it just can't seem to retrieve the image.

The code to download the image is in the viewdidload() func of the download file

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]

} }

Looks like the issue here is actually your download file path isn't correct (The error being thrown is actually an NSCocoaErrorDomain rather than a networking issue--it looks like our error message is too specific to the network).

The main issue I see is that your file path looks like /file:/Users/... while I believe that file URLs are supposed to look like file:///Users/...

I typically create local files like so like so:

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

You can also use NSHomeDirectoryForUser to get the base directory for the user.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM