Skip to content

Commit

Permalink
Merge pull request #238 from PermanentOrg/vsp-842
Browse files Browse the repository at this point in the history
VSP-842 [iOS] iCloud files fail to upload sometimes
  • Loading branch information
v-rusu authored Jul 29, 2022
2 parents b0c5030 + 579e816 commit ae251c4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
6 changes: 0 additions & 6 deletions Permanent/Managers/Upload/UploadManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,6 @@ class UploadManager {
if let fileContents = file.fileContents {
file.url = fileHelper.saveFile(fileContents, named: file.id, withExtension: "jpeg", isDownload: false) ?? URL(fileURLWithPath: "")
file.fileContents = nil
} else {
do {
file.url = try fileHelper.copyFile(withURL: file.url)
} catch {
print(error)
}
}

// Save file metadata
Expand Down
12 changes: 8 additions & 4 deletions Permanent/ViewControllers/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1157,12 +1157,16 @@ extension MainViewController: FilePreviewNavigationControllerDelegate {
// MARK: - PhotoPickerViewControllerDelegate
extension MainViewController: PhotoPickerViewControllerDelegate {
func photoTabBarViewControllerDidPickAssets(_ vc: PhotoTabBarViewController?, assets: [PHAsset]) {
let alert = UIAlertController(title: "Preparing Files...".localized(), message: nil, preferredStyle: .alert)
present(alert, animated: true)
viewModel?.didChooseFromPhotoLibrary(assets, completion: { [self] urls in
guard let currentFolder = viewModel?.currentFolder else {
return showErrorAlert(message: .cannotUpload)
dismiss(animated: true) { [self] in
guard let currentFolder = viewModel?.currentFolder else {
return showErrorAlert(message: .cannotUpload)
}

processUpload(toFolder: currentFolder, forURLS: urls)
}

processUpload(toFolder: currentFolder, forURLS: urls)
})
}
}
8 changes: 7 additions & 1 deletion Permanent/ViewModels/FilesViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,13 @@ class FilesViewModel: NSObject, ViewModelInterface {
return
}

urls.append(imageURL)
do {
let localURL = try FileHelper().copyFile(withURL: imageURL)
urls.append(localURL)
} catch {
print(error)
}

dispatchGroup.leave()
}
}
Expand Down

0 comments on commit ae251c4

Please sign in to comment.