Home > front end >  firebase upload error Domain=NSItemProviderErrorDomain Code=-1000 "Cannot load representation o
firebase upload error Domain=NSItemProviderErrorDomain Code=-1000 "Cannot load representation o

Time:08-03

So I set up a PHPickerViewController, and it uploads the videos from the camera roll (slowly ugh, but it does it). Sometimes, the video uploads. Other times, I get this error (especially with longer videos), and I'm unsure why:

Error Domain=NSItemProviderErrorDomain Code=-1000 "Cannot load representation of type com.apple.quicktime-movie" UserInfo={NSLocalizedDescription=Cannot load representation of type com.apple.quicktime-movie}

Here is my code:

func uploadVideo(videoURL: URL)
    {
        let storage = Storage.storage()
        let storageRef = storage.reference()
        
        let videoRef = storageRef.child("rPosts/\(uid!)/\(fileID).mov")
        let metadata = StorageMetadata()
        metadata.contentType = "video/quicktime"
        
        var videoData: Data = Data()
        
        do
        {
            videoData = try Data(contentsOf: videoURL)
        }
        catch
        {
            print(error.localizedDescription)
            return
        }
        
        videoRef.putData(videoData, metadata: metadata)
        { (metaData, error) in
            guard error == nil else
            {
                self.errorLabel.text = error!.localizedDescription
                return
            }
            
            print("greenchecktimeebabyyyy AHHHH")
        }
    }

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

            for result in results {
                
                print("made result")
                var went = false
                
                result.itemProvider.loadFileRepresentation(forTypeIdentifier: "com.apple.quicktime-movie")
                { videoURL, error in
                    result.itemProvider.loadFileRepresentation(forTypeIdentifier: "com.apple.quicktime-movie") { 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 error is saying that NSItemProvider cannot load your video file. When loading, you're setting the identifier to com.apple.quicktime-movie which refers to .mov files.

With that in mind, perhaps you're trying to load a .mp4. Try to use Apple's UniformTypeIdentifiers framework, so your identifier would be: UTType.movie.identifier.

Note: don't forget to import UniformTypeIdentifiers

  • Related