微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Firebase Storage 的 ref.write(toFile) 显示发生未知错误,请检查服务器响应

如何解决Firebase Storage 的 ref.write(toFile) 显示发生未知错误,请检查服务器响应

我正在尝试从 Firebase Storage 下载视频并将其本地存储到我的设备中,如下所示,但出现错误 An unkNown error occurred,please check the server response.

当这看起来类似于 Firebase 的 documentation

时,我不知道我做错了什么

这是我的代码

    let videoRef = storage.reference(forURL: "https://firebasestorage.googleapis.com/v0/b/bolar-ea96c.appspot.com/o/ChatVideos%2FL1f4FHqRlMYRJvUxP31c7FwI7Wj2:eUuKNzOByBcjQbwAZXmzY4iPj952%2F98E983A0-0E91-4DAB-BF50-16C1AF2E1894%2FIMG_4776.MOV?alt=media&token=1867f82e-e24e-43b9-99ad-5d21163f1469")
    let paths = NSSearchPathForDirectoriesInDomains(.downloadsDirectory,.userDomainMask,true)
    let documentsDirectory = paths[0]
    let docURL = URL(string: documentsDirectory)!
    let localUrl = docURL.appendingPathComponent("\(self.chatRoomId)/\(chatId)")
    if !FileManager.default.fileExists(atPath: localUrl.absoluteString) {
        do {
            let downloadTask = videoRef.write(toFile: localUrl) { (videoLocalUrl,error) in //download the video from Storage and store it to a localUrl
                if let error = error {
                    print("Error getting video URL from \(videoUrl.absoluteString) \nWith error = \(error.localizedDescription)")
                    return //MARK: Getting error here
                }
                chat.video?.videoLocalUrl = videoLocalUrl!
                tempChats.append(chat)
                print("Successfully downloaded video from \(videoLocalUrl!)")
            }
            downloadTask.observe(.success) { (snapshot) in
                print("Completed \(snapshot)")
            }
        }
    }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。