I am trying to upload a movie url to firebase and firebase is telling me "Invalid url pair".
I think the reason for this is because in my console I am getting an error that says:
Failed to issue sandbox extension for file
I'm not sure why but I don't think apple allows you to upload a movie url to a server for some reason? How do you get around this?
I already tried using CFURLStartAccessingSecurityScopedResource(_) which I saw from another answer:
picker.dismiss(animated: true)
// Get the movie URL from camera
let movieURL = info[.mediaURL] as! CFURL
// allow access to the movieURL.
CFURLStartAccessingSecurityScopedResource(movieURL)
// Upload the url to firebase.
Storage.storage().reference().child("WORK").child("YEET").putFile(from: movieURL as URL, metadata: nil) { metadata, error in
if let error = error {
print("There was an error \(error)")
} else {
print("Success")
}
// Stop allowing access to the movieURL
CFURLStopAccessingSecurityScopedResource(movieURL)
}
}
And it didn't work :(.
How do i allow access to a movie URL so I can upload it to firebase? Or maybe there is something else wrong? Idk anything helps, thanks in advance!
I figured it out.
So what I ended up doing was I got the URL of the movie, and then the data of the movies URL using Data(contentsOf: movieURL)
and then I saved the data to the file manager and used the URL of the file manger, instead of the URL of the movie to upload it to firebase. This worked for me. Hopefully that made sense.
Also if you don't want to save the URL in the file manager because movies take a lot of data, after you save it to firebase you can just delete it from file manager using FileManager.default.removeItem(atPath: "path of file")
Here is my code:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
picker.dismiss(animated: true)
// Get the movie URL from camera roll
if let movieURL = info[.mediaURL] as? URL {
do {
// Get the data of the URL.
let movieData = try Data(contentsOf: movieURL)
// Define the path in filemanager where you will save the Movie
guard let path = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first?.appendingPathComponent("93222231") else { print("No path rip"); return }
do {
// Put the movie data into a file in the file manager.
try movieData.write(to: path)
// Save the file to firebase and check for errors.
Storage.storage().reference().child("Videos").child("test.m4v").putFile(from: path, metadata: nil) { metadata, error in
if let error = error {
print("There was an error in firebase \(error.localizedDescription)")
} else {
print("Success.")
}
do {
try FileManager.default.removeItem(atPath: path.path)
} catch let error {
print("Error deleting from filemanager \(error.localizedDescription)")
}
}
} catch let error {
print("There was an error writing movieData \(error.localizedDescription)")
}
} catch let error {
print("there was an error getting contentsOF movieURL. \(error.localizedDescription)")
}
} else {
print("This did not work.")
}
}
Hope this helps someone as it has worked for me.