本文介绍了快速将音频文件上传到Firebase的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试将m4a文件上传到Firebase Storage,但始终收到错误"Error Domain = FIRStorageErrorDomain代码= -13000",发生未知错误,请检查服务器响应.ResponseBody =无法完成上传.当前大小为38298.预计最终大小为34554.
Hi I try to upload a m4a file to Firebase Storage but always got error " Error Domain=FIRStorageErrorDomain Code=-13000 "An unknown error occurred, please check the server response."ResponseBody=Can not finalize upload. Current size is 38298. Expected final size is 34554.
这是我的代码:
func uploadSound(localFile: URL) {
let storageRef = FIRStorage.storage().reference()
let imagesRef = storageRef.child("upload")
let fileName = "/" + self.deviceID + ".m4a"
let uploadTask = spaceRef.putFile(localFile, metadata: nil) { metadata, error in
if let error = error {
print(error)
} else {
// Metadata contains file metadata such as size, content-type, and download URL.
let downloadURL = metadata!.downloadURL()
}
}
}
感谢帮助.谢谢
推荐答案
您创建以下两个变量,它们都未使用:
You create the following variables, both of which are unused:
let imagesRef = storageRef.child("upload")
let fileName = "/" + self.deviceID + ".m4a"
上传时,您正在呼叫:
// where is `spaceRef`?
spaceRef.putFile(localFile, metadata: nil)
作为建议,也许尝试:
let newFileRef = imagesRef.child(fileName)
let uploadTask = newFileRef.putFile(localFile, metadata: nil) { metadata, error in
if let error = error {
print(error)
} else {
// Metadata contains file metadata such as size, content-type, and download URL.
let downloadURL = metadata!.downloadURL()
}
}
这篇关于快速将音频文件上传到Firebase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!