Can';t将视频上传到iOS 13上的Firebase存储
在iOS 12上工作得非常好 简单样板代码:Can';t将视频上传到iOS 13上的Firebase存储,ios,swift,firebase,firebase-storage,ios13,Ios,Swift,Firebase,Firebase Storage,Ios13,在iOS 12上工作得非常好 简单样板代码: let storageRef = storage.reference().child("\(profile.studioCode)/\(selected.classId)/\(uploadDate)") //Upload file and metadata let uploadTask = storageRef.putFile(from: videoURL, metadata: metadata)
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中,它可以完美地上传。任何帮助或见解都将不胜感激。谢谢 我有一个类似的问题,但这里有一个简单的解决方法:您需要使用“.putData”而不是“.putFile”,并在上传时指定MIME类型
let metadata = StorageMetadata()
//specify MIME type
metadata.contentType = "video/quicktime"
//convert video url to data
if let videoData = NSData(contentsOf: videoURL) as Data? {
//use 'putData' instead
let uploadTask = storageRef.putData(videoData, metadata: metadata)
}
我有一个类似的问题,但这里有一个简单的解决方法:您需要使用“.putData”而不是“.putFile”,并在上传时指定MIME类型
let metadata = StorageMetadata()
//specify MIME type
metadata.contentType = "video/quicktime"
//convert video url to data
if let videoData = NSData(contentsOf: videoURL) as Data? {
//use 'putData' instead
let uploadTask = storageRef.putData(videoData, metadata: metadata)
}
我是如何修复它的:
事实证明,iOS 13中的文件路径与iOS 12中的不同:
iOS12路径:
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
注意iOS13路径中的额外“.”。我的解决方案是,在imagePickerController完成PickingMediaWithInfo函数的内部,将文件复制到另一个临时目录中,从那里上传,然后删除副本
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中的文件路径与iOS 12中的不同:
iOS12路径:
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
注意iOS13路径中的额外“.”。我的解决方案是,在imagePickerController完成PickingMediaWithInfo函数的内部,将文件复制到另一个临时目录中,从那里上传,然后删除副本
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
}
您是否检查以确保此
“\(profile.studioCode)/\(selected.classId)/\(uploadDate)
有效?即没有零和有效数据?可能会添加打印(\(profile.studioCode)/\(selected.classId)/\(uploadDate)
您是否检查以确保此”\(profile.studioCode)/\(selected.classId)/\(uploadDate)
有效?即没有零和有效数据?可能会添加打印(\(profile.studioCode)/\(selected.classId)/\(uploadDate)”
我没有尝试过这个,但我确实很好奇。这比我最终修复它的方式更简单、更安全。我有机会测试后会与你联系。太棒了!谢谢你哇,这很有效。太棒了!所以我的Iphone或Iphone XR等模拟器不会上传视频,但我的旧Iphone 6s和5会上传视频。一旦我使用了这个代码,它就可以在一个平台上工作ll phones.Crazy…你知道你必须使用putData而不是putFile吗?这非常有效,谢谢!FWIW,我不需要指定contentType
(或任何元数据)我没有尝试过这个,但我确实很好奇。这比我最终修复它的方式更简单、更安全。我有机会测试后会给你回复。太棒了!谢谢你哇,这很有效。太棒了!所以我的Iphone或Iphone XR等模拟器不会上传视频,但我的旧Iphone 6s和5会。一旦我使用了这个代码,它可以在所有phon上运行疯狂…你知道你必须使用putData而不是putFile吗?这非常有效,谢谢!FWIW,我不需要指定contentType
(或者任何元数据)