从Firebase存储下载时出错 [英] Error when downloading from Firebase storage

查看:660
本文介绍了从Firebase存储下载时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用新的Firebase存储进行基本的上传/下载工作。上传工作正常,但我无法将文件下载到设备。有人可以请说明我做错了什么。谢谢!

  func downloadAudio(){

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

让pathReference = storageRef.child(testAudio / audio_test.m4a)

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

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

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

PRINTS:
$ b 错误 - 可选(错误域= FIRStorageErrorDomain代码= -13000发生未知错误,请检查服务器响应。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 =发生未知错误,请检查服务器响应。解决方案

这不是一个存储错误,它实际上是你正在尝试写入的文件的问题。



看起来像 URLByAppengingString 应该是 fileURLWithPath 来获取文件系统的URL(每个 NSFileManager创建目录错误518 NSFileWriteUnsupportedSchemeError )。

长期来看,我们需要将其作为看到相关错误而不是阅读网络响应。


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."

这篇关于从Firebase存储下载时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆