将视频文件上传到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.

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