将视频上传到Firebase存储(未知错误)

我要做什么::从图像选择器中获取视频并将其上传到Firebase存储,并在Firestore中创建一个指向该视频的文档。

当前问题是什么:Xcode抛出一个未知错误。无法将视频上传到存储。 (下面的控制台响应)

我的代码:

if self.fireImage == nil,description == "",self.fireURL != nil{
                                
    print(self.fireURL!)
    storageVideoRef.putFile(from: self.fireURL! as URL,metadata: nil) { (storageMetaData,error) in
    if error != nil{
        print(error!.localizedDescription)
        return
        }
        print("is in database")
            storageVideoRef.downloadURL { (url,error) in
            if let metaVideoUrl = url?.absoluteString{
                                            
            docRef.getDocument { (doc,err) in
                if let doc = doc,doc.exists{
                print("Post ID already taken")
                }else{
                                                    
                print("Post gets created")
                                                
                self.db.collection("posts").document(combined).setData([
                    "hasLiked": [],"likes": self.likes,"video": metaVideoUrl,"postType": 6,"profileImage": pfp!,"time": date,"uid": self.userID,"username": fullname!,"postID": combined,]) { err in
                    if let err = err {
                        print("Error writing document: \(err)")
                    } else {
                        print("Post Document successfully written!")
                            }
                        }
                    }
                }
            }
        }
    }
}

控制台告诉我的内容:

file:///Users/janjan/library/Developer/CoreSimulator/Devices/63A8A6CC-ED10-49C2-8C24-EC6EF9919061/data/Containers/Data/PluginKitPlugin/601B4FBB-1343-4AF0-BFF4-C44CFBF3E633/tmp/trim.B03B576D-1887-4C6F-A0AE-93689A8A5EDB.MOV
2020-07-06 17:51:42.891754+0200 LiFit[20902:2197419] Task <18AD8076-F410-4E50-997E-FF77DFF5F760>.<1> finished with error [-1] Error Domain=nsurlerrordomain Code=-1 "unknown error" UserInfo={NSErrorFailingURLStringKey=https://firebasestorage.googleapis.com/v0/b/lifit-98bf5.appspot.com/o/postVideos%2FI47GVyorqqVVsn6O29qRUavz1it2203458125?uploadType=resumable&name=postVideos%2FI47GVyorqqVVsn6O29qRUavz1it2203458125&upload_id=AAANsUmSPY8KB9XMpYvZxJqWiHPrwz4FT9uPxfKy8yyf-eIvrcRVEP0lkWDXWiSWy9i1q7hkOxdGqinJvkALDrskCIk&upload_protocol=resumable,NSErrorFailingURLKey=https://firebasestorage.googleapis.com/v0/b/lifit-98bf5.appspot.com/o/postVideos%2FI47GVyorqqVVsn6O29qRUavz1it2203458125?uploadType=resumable&name=postVideos%2FI47GVyorqqVVsn6O29qRUavz1it2203458125&upload_id=AAANsUmSPY8KB9XMpYvZxJqWiHPrwz4FT9uPxfKy8yyf-eIvrcRVEP0lkWDXWiSWy9i1q7hkOxdGqinJvkALDrskCIk&upload_protocol=resumable,_NSURLErrorRelatedURLSessionTaskErrorKey=(
    "BackgroundUploadTask <18AD8076-F410-4E50-997E-FF77DFF5F760>.<1>"
),_NSURLErrorFailingURLSessionTaskErrorKey=BackgroundUploadTask <18AD8076-F410-4E50-997E-FF77DFF5F760>.<1>,NSLocalizedDescription=unknown error}
An unknown error occurred,please check the server response.
``
iCMS 回答:将视频上传到Firebase存储(未知错误)

好像是iOS 13问题,文件路径与所有其他版本略有不同。

我通过检查上传设备是否在iOS 13上,然后更改其工作路径来解决此问题。

代码如下:

else if let videoURL = info[.mediaURL] as? URL {
            fireURL = videoURL
            
            do {
                if #available(iOS 13,*) {
                    //If on iOS13 slice the URL to get the name of the file
                    let urlString = videoURL.relativeString
                    let urlSlices = urlString.split(separator: ".")
                    //Create a temp directory using the file name
                    let tempDirectoryURL = URL(fileURLWithPath: NSTemporaryDirectory(),isDirectory: true)
                    fireURL = tempDirectoryURL.appendingPathComponent(String(urlSlices[1])).appendingPathExtension(String(urlSlices[2]))

                    //Copy the video over
                    try FileManager.default.copyItem(at: videoURL,to: fireURL!)
                }
            }
            catch let error {
                print(error.localizedDescription)
            }
本文链接:https://www.f2er.com/1989666.html

大家都在问