1

I'm saving a recorded video on the device. To be able to upload it now, I need to create a Data object. The following function gets called, after the local file has been created.

I have a print statement once the file has been created. localIdentifier = "BE04AABA-BC42-413D-BC32-26B5F1DEC2A1/L0/001" correctly printed.

func uploadVideo(_ userID: String, _ videoURL: String, completion: @escaping (_ url: URL?) -> Void) {

    print("videoURL = \(videoURL)") // *1

    let fileManager = FileManager.default
    if fileManager.fileExists(atPath: videoURL) {
        print("FILE AVAILABLE")
    } else {
        print("FILE NOT AVAILABLE") // *2
    }

    if let videoData = NSData(contentsOfFile: videoURL) {
        // not executed
    }
}

After execution I get the following print statement.

*1 videoURL = file:///var/mobile/Containers/Data/Application/42572E4F-AC7F-4444-8641-111111111/Documents/201889991.mov

*2 FILE NOT AVAILABLE

But the correct video file is present in the phone's library and is played by a video player view. I have triple checked, but the file is created BEFORE this function gets called.

What am I missing?

Question 2. I need the object as Data, not as NSData, requested by the Firebase upload function. Would casting as? Data do it?

Help is very appreciated.

David Seek
  • 15,533
  • 14
  • 94
  • 125
  • 2
    `"file:///var/mobile/.../201889991.mov"` is not a path to a file, but a string containing a "file URL". The error is probably where you created that string, using `absoluteString` or `description` to convert a URL to a string (instead of `path`). Compare http://stackoverflow.com/questions/34135305/nsfilemanager-defaultmanager-fileexistsatpath-returns-false-instead-of-true for a similar issue. – Martin R Dec 04 '16 at 21:31
  • yeah. my bad. i have casted the url as string for this function. now i'm sending the url and put url.path. now it's working. thank you very much. i have upvoted the other question. – David Seek Dec 04 '16 at 21:36
  • do you want to answer here? maybe it will help someone else. if you want to flag it as dublicate, fine by me as well. but you helped me. thank you very much – David Seek Dec 04 '16 at 21:38
  • ps. i was honestly searching for help, but i did not find the other thread. wasn't perfectly easy to know what to look for – David Seek Dec 04 '16 at 21:38

0 Answers0