Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to upload a Video from FileManager to Firebase storage?

I am trying to upload a video to firebase storage that is saved in FileManager as a URL looking like this file:///Users/admin/Library/Developer/CoreSimulator/Devices/D9BA697D-2ACA-4C4F-BE64-9004016A8500/data/Containers/Data/Application/1133A56A-B92F-4A8A-B9D9-0A8180607B93/Documents/videorecording.mp4. I tried uploading it like this:

private func persistVideoToStorage(id: String, video: URL) {
        let ref = FirebaseManager.shared.storage.reference(withPath: id)
        ref.putData(video, metadata: nil) { metadata, err in
            if let err = err {
                print(err)
                return
            }
            ref.downloadURL { url, err in
                if let err = err {
                        print(err)
                        return
                }
                guard let url = url else { return }
            }
        }
    }

But I need to upload the type of Data and cannot convert URL to Data.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Try something like this:

 do {
     let videoData = try Data(contentsOf: video)
     //....
     ref.putData(videoData, metadata: nil)
     //....
 } catch {
     print("-- Error: \(error)")
 }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading