Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/102.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何使用视频url将视频上载到Firebase存储_Ios_Swift_Firebase_Firebase Storage - Fatal编程技术网

Ios 如何使用视频url将视频上载到Firebase存储

Ios 如何使用视频url将视频上载到Firebase存储,ios,swift,firebase,firebase-storage,Ios,Swift,Firebase,Firebase Storage,我一直在尝试实现一个功能,通过该功能,我可以使用视频url将视频上传到Firebase存储 static func savePostVideo(userId: String, caption:String,postId: String, url:URL, metadata: StorageMetadata, storagePostRef: StorageReference, onSuccess: @escaping()->Void, onError: @escaping(_ e

我一直在尝试实现一个功能,通过该功能,我可以使用视频url将视频上传到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()
                       }
                       
                   }
           }
   }
      
但是,每当我运行代码时,调试器上总是出现以下错误:

从后台请求NSURLSessionPloadTask时出错

我已经实现了一个类似的上传照片的方法,它工作得非常好,但不幸的是,我不能用这一个同样的方法。
如果需要,我可以提供其他信息

无法直接从URL将数据写入云存储。您首先必须从URL下载数据,然后将其上载到存储器。或者,如果符合您的用例,您也可以将外部URL存储在数据库中。看,如果你能提供第一个选项的例子,那就更好了。你是说从URL下载数据?是,从URL下载数据。抱歉,我只是一个初学者。我之前评论中的链接显示了从Swift中的URL下载数据的一种方法。因为这似乎是您当前代码中缺少的内容。若你们很难让下载的内容对你们有用,那个就在下面贴一个新问题。