无法将视频上传到iOS 13上的Firebase存储 [英] Can't Upload Video to Firebase Storage on iOS 13

查看:148
本文介绍了无法将视频上传到iOS 13上的Firebase存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iOS 12上运行良好.

Works perfectly fine on iOS 12.

简单的样板代码:

let storageRef = storage.reference().child("\(profile.studioCode)/\(selected.classId)/\(uploadDate)")

        //Upload file and metadata
        let uploadTask = storageRef.putFile(from: videoURL, metadata: metadata)

        //Listen for state changes and, errors, and completion of the upload
        uploadTask.observe(.resume) { (snapshot) in
            //upload resumed or started
        }

        uploadTask.observe(.pause) { (snapshot) in
            //upload paused
        }

        uploadTask.observe(.progress) { (snapshot) in
            //upload progress
        }

        uploadTask.observe(.success) { (snapshot) in
            //upload successful
        }

        uploadTask.observe(.failure) { (snapshot) in
            //upload failed
        }

给我:

Error Domain=FIRStorageErrorDomain Code=-13000 "An unknown error occurred, please check the server response."

我已经将Cocoapods和Firebase更新到最新版本,尝试允许任意加载,并尝试注销并返回应用程序以重置我的身份验证令牌.在iOS 13中,它会立即在上传时抛出该错误,但在iOS 12中,它会上传完全正常.任何帮助或见识将不胜感激.谢谢!

I've updated Cocoapods and Firebase to the newest versions, tried allowing arbitrary loads, and tried signing out and back into the app to reset my auth token. In iOS 13 it throws that error immediately on upload, but on iOS 12 it uploads perfectly fine. Any help or insight would be greatly appreciated. Thanks!

推荐答案

我最终如何解决它:

事实证明,iOS 13中的文件路径与iOS 12中的文件路径不同:

How I ended up fixing it:

It turns out that file paths are different in iOS 13 than iOS 12:

iOS12路径:

file:///private/var/mobile/Containers/Data/Application/DF9C58AB-8DCE-401B-B0C9-2CCAC69DC0F9/tmp/12FD0C43-F9A0-4DCB-96C3-18ED83FED424.MOV

file:///private/var/mobile/Containers/Data/Application/DF9C58AB-8DCE-401B-B0C9-2CCAC69DC0F9/tmp/12FD0C43-F9A0-4DCB-96C3-18ED83FED424.MOV

iOS13路径:

file:///private/var/mobile/Containers/Data/PluginKitPlugin/5DFD037B-AC84-463B-84BD-D0C1BEC00E4C/tmp/trim.7C8C6CD1-97E7-44D4-9552-431D90B525EA.MOV

file:///private/var/mobile/Containers/Data/PluginKitPlugin/5DFD037B-AC84-463B-84BD-D0C1BEC00E4C/tmp/trim.7C8C6CD1-97E7-44D4-9552-431D90B525EA.MOV


请注意多余的.".在iOS13路径中.我的解决方案是,在我的imagePickerController didFinishPickingMediaWithInfo函数内部,将文件复制到另一个临时目录,从那里上传它,然后删除副本.


Note the extra '.' in the iOS13 path. My solution was to, inside of my imagePickerController didFinishPickingMediaWithInfo function, copy the file into another temp directory, upload it from there, and then delete the copy.

 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)
                let targetURL = tempDirectoryURL.appendingPathComponent(String(urlSlices[1])).appendingPathExtension(String(urlSlices[2]))

                //Copy the video over
                try FileManager.default.copyItem(at: videoURL, to: targetURL)

                picker.dismiss(animated: true) {
                    self.videoRecorded = false
                    self.showUpload(targetURL)
                }
            }
            else {
                //If on iOS12 just use the original URL
                picker.dismiss(animated: true) {
                    self.videoRecorded = false
                    self.showUpload(videoURL)
                }
            }
        }
        catch let error {
            //Handle errors
        }

这篇关于无法将视频上传到iOS 13上的Firebase存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆