简体   繁体   中英

Error when downloading from Firebase storage

I am trying to get basic upload/download working with the new Firebase storage. Uploading worked fine but I am unable to download the file to the device. Can someone please shed some light on what I am doing wrong. Thanks!

func downloadAudio() {

let storageRef = FIRStorage.storage().reference()

let pathReference = storageRef.child("testAudio/audio_test.m4a")

let localURL = getDocumentsDirectory().URLByAppendingPathComponent("audio_test2.m4a")

let downloadTask = pathReference.writeToFile(localURL) { (URL, error) -> Void in
  if (error != nil) {

    print("ERROR - ", error.debugDescription)
  } else {
    print("SUCCESS - ", URL)
  }
 }
}

PRINTS:

ERROR - Optional(Error Domain=FIRStorageErrorDomain Code=-13000 "An unknown error occurred, please check the server response." UserInfo={ResponseErrorDomain=NSCocoaErrorDomain, object=testAudio/audio_test.m4a, NSURL=/Users/Ben/Library/Developer/CoreSimulator/Devices/02AF50F2-E9BE-4EED-A3BE-485D63264731/data/Containers/Data/Application/31BDED56-0135-4E70-943E-F897080768D6/Documents/, bucket=mydevslopesapp.appspot.com, ResponseErrorCode=518, NSLocalizedDescription=An unknown error occurred, please check the server response.})

This is not a storage error, it's actually an issue with the file you're attempting to write to.

Looks like URLByAppengingString should be fileURLWithPath to get a file system URL (per NSFileManager creating directory error 518 NSFileWriteUnsupportedSchemeError ).

Long term we need to fish this out and serve it as a "see relevant error" rather than "read network response."

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