[英]firebase upload error Domain=NSItemProviderErrorDomain Code=-1000 "Cannot load representation of type
So I set up a PHPickerViewController
, and it uploads the videos from the camera roll (slowly ugh, but it does it).所以我设置了一个
PHPickerViewController
,它从相机胶卷上传视频(慢慢地,但它确实做到了)。 Sometimes, the video uploads.有时,视频会上传。 Other times, I get this error (especially with longer videos), and I'm unsure why:
其他时候,我会收到此错误(尤其是较长的视频),我不确定原因:
Error Domain=NSItemProviderErrorDomain Code=-1000 "Cannot load representation of type com.apple.quicktime-movie" UserInfo={NSLocalizedDescription=Cannot load representation of type com.apple.quicktime-movie}
错误域=NSItemProviderErrorDomain 代码=-1000“无法加载 com.apple.quicktime-movie 类型的表示” UserInfo={NSLocalizedDescription=无法加载 com.apple.quicktime-movie 类型的表示}
Here is my code:这是我的代码:
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!) }
}
}
}
The error is saying that NSItemProvider
cannot load your video file.错误是说
NSItemProvider
无法加载您的视频文件。 When loading, you're setting the identifier to com.apple.quicktime-movie
which refers to .mov
files.加载时,您将标识符设置为
com.apple.quicktime-movie
引用.mov
文件。
With that in mind, perhaps you're trying to load a .mp4
.考虑到这一点,也许您正在尝试加载
.mp4
。 Try to use Apple's UniformTypeIdentifiers
framework, so your identifier would be: UTType.movie.identifier
.尝试使用Apple 的
UniformTypeIdentifiers
框架,因此您的标识符将是: UTType.movie.identifier
。
Note: don't forget to import UniformTypeIdentifiers
注意:不要忘记
import UniformTypeIdentifiers
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.