Home > Mobile >  Track progress of PHPickerViewController video upload, takes way too long to upload videos over 5 mi
Track progress of PHPickerViewController video upload, takes way too long to upload videos over 5 mi

Time:08-06

I set this up in my code and it works fine. I try to download the URL from user library, and upload it to Firebase Storage through another function, but for videos over 5 minutes, it seems to take forever to download before uploading to the database, to the point where it seems like nothing is happening or going to happen. Is there any way I can track the progress of the download? If not, how can I at least quicken the process?

extension postingRViewController: PHPickerViewControllerDelegate
{
    func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {
            picker.dismiss(animated: true, completion: nil)
        
            progressWheel.startAnimating()
            progressWheel.alpha = 1

            for result in results {
                
                print("made result")
                var went = false
                
                result.itemProvider.loadFileRepresentation(forTypeIdentifier: UTType.movie.identifier)
                { videoURL, error in
                    result.itemProvider.loadFileRepresentation(forTypeIdentifier: UTType.movie.identifier) { videoURL, error in
                        
                        assert(Thread.isMainThread == false)

                        let directory = NSTemporaryDirectory()
                        let fileName = NSUUID().uuidString.appending(".mov")
                        
                        print("loading")
                        went = true
                        
                        if let videoURL = videoURL,
                           let copiedURLFile = NSURL.fileURL(withPathComponents: [directory, fileName]) {
                            try! FileManager.default.copyItem(at: videoURL, to: copiedURLFile)
                            DispatchQueue.main.async {
                                // the videourl is deleted. Only copiedURLFile exists
                                // upload_to_firebase(video url)
                                self.uploadVideo(videoURL: copiedURLFile)
                                print("uploaded to the cloud")

                                // after the video is presented or the file uploaded, delete copiedURLFile
                            }
                        }
                        else { print(error!) }
                }
            }
        }

CodePudding user response:

The issue happened due to nested loadFileRepresentation(forTypeIdentifier:).

  • Related