Can't Upload video URL to Firebase Storage

44 views Asked by At

I'm trying to create a chat application in Xcode using Swift and Firebase. When I send an image in the chat, there is no problem. The image URL is saved in Firebase and it loads in the chat itself. However, when I try to upload a video, only a photo is sent instead of the video, and only the URL of the resulting image appears in Firebase, not the video.

static func saveVideoMessage(url: URL, id: String, onSuccess: @escaping(_ value: Any) -> Void, onError: @escaping(_ errorMessage: String) -> Void) {
    let ref = Ref().storageSpecificVideoMessage(id: id)
    ref.putFile(from: url, metadata: nil) { (metadata, error) in
        if error != nil {
            onError(error!.localizedDescription)
        }
        ref.downloadURL(completion: { (videoUrl, error) in
            if let thumbnailImage = self.thumbnailImageForFileUrl(url) {
                StorageService.savePhotoMessage(image: thumbnailImage, id: id, onSuccess: { (value) in
                    if let dict = value as? Dictionary<String, Any> {
                        var dictValue = dict
                        if let videoUrlString = videoUrl?.absoluteString {
                            dictValue["videoUrl"] = videoUrlString
                        }
                        onSuccess(dictValue)
                    }
                }, onError: { (errorMessage) in
                    onError(errorMessage)
                })
            }
        })
    }
}

I have no idea how to handle this. Could someone please help me?

0

There are 0 answers