Firebase 上传错误 域=NSItemProviderErrorDomain Code=-1000 "无法加载类型的表示形式



所以我设置了一个PHPickerViewController,它从相机胶卷上传视频(慢慢地,但它做到了(。有时,视频会上传。其他时候,我会遇到这个错误(尤其是较长的视频(,我不确定为什么:

错误域=NSItemProviderErrorDomain代码=-1000";无法加载类型为com.apple.quicktime movie"的表示形式;UserInfo={NSLocalizedDescription=无法加载com.apple.quicktime movie}类型的表示

这是我的代码:

func uploadVideo(videoURL: URL)
{
let storage = Storage.storage()
let storageRef = storage.reference()

let videoRef = storageRef.child("rPosts/(uid!)/(fileID).mov")
let metadata = StorageMetadata()
metadata.contentType = "video/quicktime"

var videoData: Data = Data()

do
{
videoData = try Data(contentsOf: videoURL)
}
catch
{
print(error.localizedDescription)
return
}

videoRef.putData(videoData, metadata: metadata)
{ (metaData, error) in
guard error == nil else
{
self.errorLabel.text = error!.localizedDescription
return
}

print("greenchecktimeebabyyyy AHHHH")
}
}
extension postingRViewController: PHPickerViewControllerDelegate
{
func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {
picker.dismiss(animated: true, completion: nil)
for result in results {

print("made result")
var went = false

result.itemProvider.loadFileRepresentation(forTypeIdentifier: "com.apple.quicktime-movie")
{ videoURL, error in
result.itemProvider.loadFileRepresentation(forTypeIdentifier: "com.apple.quicktime-movie") { videoURL, error in

assert(Thread.isMainThread == false)
let directory = NSTemporaryDirectory()
let fileName = NSUUID().uuidString.appending(".mov")

print("loading")
went = true
if let videoURL = videoURL,
let copiedURLFile = NSURL.fileURL(withPathComponents: [directory, fileName]) {
try! FileManager.default.copyItem(at: videoURL, to: copiedURLFile)
DispatchQueue.main.async {
// the videourl is deleted. Only copiedURLFile exists
// upload_to_firebase(video url)
self.uploadVideo(videoURL: copiedURLFile)
print("uploaded to the cloud")
// after the video is presented or the file uploaded, delete copiedURLFile
}
}
else { print(error!) }
}
}
}

错误表示NSItemProvider无法加载您的视频文件。加载时,您将标识符设置为com.apple.quicktime-movie,它指的是.mov文件。

考虑到这一点,也许您正在尝试加载.mp4。尝试使用Apple的UniformTypeIdentifiers框架,因此您的标识符将为:UTType.movie.identifier

注意:不要忘记import UniformTypeIdentifiers

相关内容

  • 没有找到相关文章

最新更新