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

将视频文件上传到Firebase存储-Swift

如何解决将视频文件上传到Firebase存储-Swift

我正在尝试将视频文件上传到Firebase存储,但是我一直收到错误消息:“发生未知错误,请检查服务器响应。”但是,我确定服务器响应良好,因为我可以毫无问题地上传图像。

这是我获取视频网址的方式(通过uiimagepickercontroller):

func imagePickerController(_ picker: UIImagePickerController,didFinishPickingMediawithInfo info: [UIImagePickerController.InfoKey : Any]) {
     guard let mediaInfo = info[.mediaType] else { return }
     let mediaType = "\(mediaInfo)"
     if mediaType == "public.movie" {
        // how we handle it if it's a video
        guard let videoURL = info[.mediaURL] as? NSURL else {return }
        videoUrl = videoURL
   }
}

我如何尝试上传视频:

        guard let videoUrl = videoUrl else { return }
        
        let videoName = NSUUID().uuidString
        let storageRef = Storage.storage().reference().child("\(videoName).mov")
        storageRef.putFile(from: videoUrl as URL,Metadata: nil) { (MetaData,error) in
             // IMPORTANT: this is where I got the error from 
            if error != nil {
                print("error uploading video: \(error!.localizedDescription)")
            } else {
                // successfully uploaded the video
                storageRef.downloadURL { (url,error) in
                    if error != nil {
                        print("error downloading uploaded videos Url: \(error!.localizedDescription)")
                    } else {
                        if let downloadUrl = url {
                            let contentType = "videoUrl" //just a var for the following func
                            self.uploadPost(for: downloadUrl,contentType: contentType) // func that uploads the url to the database
                        }
                    }
                }
            }
        }

有人可以帮助我解决为什么它不起作用,也许我需要将URL转换为mp4文件或其他内容。预先感谢!

解决方法

我找到了答案,这很简单... 发生这种情况的原因是,视频网址实际上不是“具有路径网址的文件” 所以解决方案很容易,在didFinishPicking中:

Your search - chrome-devtools://devtools/bundled/js_app.html?experiments=true&v8only=true&ws=10.0 ... - did not match any documents.

尽管如此,感谢所有帮助!即使没有任何帮助。

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