I have been trying to implement a function through which I can upload videos to Firebase storage using videos url
static func savePostVideo(userId: String, caption:String,postId: String, url:URL, metadata: StorageMetadata, storagePostRef: StorageReference, onSuccess: @escaping()->Void, onError: @escaping(_ errorMessage: String)->Void) {
storagePostRef.putFile( from: url, metadata: nil) { (storageMetadata, error) in
if error != nil {
onError(error!.localizedDescription)
return
}
storagePostRef.downloadURL { (url,error) in
if let metaImageUrl = url?.absoluteString {
let firestorePostRef = Ref.FIRESTORE_MY_POSTS_DOCUMENT_USERID(userId: userId).collection("userPosts").document(postId)
let post = Post.init(caption: caption, likes: [:], location: "", ownerId: userId, postId: postId, username: Auth.auth().currentUser!.displayName!, avatar: Auth.auth().currentUser!.photoURL!.absoluteString, mediaUrl: metaImageUrl, date: Date().timeIntervalSince1970, likeCount: 0)
guard let dict = try? post.toDictionary() else {return}
firestorePostRef.setData(dict) { (error) in
if error != nil {
onError(error!.localizedDescription)
return
}
Ref.FIRESTORE_TIMELINE_DOCUMENT_USERID(userId: userId).collection("timelinePosts").document(postId).setData(dict)
Ref.FIRESTORE_COLLECTION_ALL_POSTS.document(postId).setData(dict)
onSuccess()
}
}
}
}
However, whenever I run the code I keep getting this error on the debugger:
error requesting a NSURLSessionUploadTask from background.
I have implemented a similar method to upload photos and it works perfectly fine but unfortunately I couldn't do the same with this one. I can provide additional information if needed