In one of my view controllers, I'm using PHPickerViewController. When I get my results, I then upload the URL to Firebase. It works fine, but with this line of code, try! FileManager.default.copyItem(at: videoURL, to: copiedURLFile)
, I'm not sure if I'm doubling the amount of time it takes for the video to upload. Honestly, I saw this line in a tutorial and added it absentmindedly, is it really necessary, and if not, will it save me time (especially since I sometimes get errors for longer videos)?
result.itemProvider.loadFileRepresentation(forTypeIdentifier: UTType.movie.identifier)
{ videoURL, error in
assert(Thread.isMainThread == false)
let directory = NSTemporaryDirectory()
let fileName = NSUUID().uuidString.appending(".mov")
if let videoURL = videoURL,
let copiedURLFile = NSURL.fileURL(withPathComponents: [directory, fileName]) {
try! FileManager.default.copyItem(at: videoURL, to: copiedURLFile)
DispatchQueue.main.async {
observer.hasUploaded = true
observer.uploadVideo(videoURL: copiedURLFile, uid: self.uid!, fileID: self.fileID, progressWheel: self.progressWheel, errorLabel: self.errorLabel, progressView: self.progressView, progressLabel: self.progressLabel)
print("uploaded to the cloud")
}
}
else { print(error!); print("video might be too long") /*alert*/}
}