我一直在尝试实现一项功能,通过该功能可以使用视频网址将视频上传到Firebase存储
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()
}
}
}
}
但是,每当我运行代码时,我都会在调试器上不断收到此错误:
从后台请求NSURLSessionUploadTask时出错。
我已经实现了一种类似的方法来上传照片,并且效果很好,但不幸的是,我对此却无法做到。 如果需要,我可以提供其他信息