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.