使用putFIle Swift 5将视频上传到Firebase

时间:2019-11-20 21:33:08

标签: swift firebase firebase-storage

我一直试图将视频从摄像头角色上传到Firebase,但无法正常工作。

URL可以正常打印,但不确定为什么它不能正常工作。我在控制台中收到错误代码-1:

  

<1>完成,错误为[-1]错误域= NSURLErrorDomain代码= -1“未知错误”

    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {

        if let videoURL = info[.mediaURL] as? URL {
            print("Here is the URL: \(videoURL)")


            let filename = "Videos/trialVideo.mov"
            Storage.storage().reference().child(filename).putFile(from: videoURL, metadata: nil) { (metadata, error) in

                if error != nil {
                    print("**** ERROR MESSAGE *** \(error?.localizedDescription)")
                    return
                }

            }
        }
        videoPicker.dismiss(animated: true, completion: nil)
    }

1 个答案:

答案 0 :(得分:0)

最后弄清楚了,我应该已经从NSURL对象创建了URL(对此是新的,如果那不是正确的术语,请更正我)

更新的代码:

    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {

        if let videoURL = info[.mediaURL] as? NSURL {
            print("Here is the URL: \(videoURL)")
            let url: URL = videoURL.absoluteString!


            let filename = "Videos/trialVideo.mov"
            Storage.storage().reference().child(filename).putFile(from: url, metadata: nil) { (metadata, error) in

                if error != nil {
                    print("**** ERROR MESSAGE *** \(error?.localizedDescription)")
                    return
                }

            }
        }
        videoPicker.dismiss(animated: true, completion: nil)
    }