Как сохранить документ в Firebase Storage - PullRequest
0 голосов
/ 27 февраля 2020

У меня есть UIDocumentPickerViewController, где пользователь может выбрать документ, когда я пытаюсь сохранить файл в хранилище Firebase, я получаю следующее:

Ошибка домена = FIRStorageErrorDomain Code = -13000 "Файл по URL: file: /// private / var / mobile / Library / Mobile% 20Documents / com ~ apple ~ CloudDocs / Documents / Documents% 20-% 20Name% E2% 80% 99s% 20MacBook% 20Pro / PDF% 20Export .compressed.pdf недоступен. " UserInfo = {NSLocalizedDescription = Файл по URL: file: /// private / var / mobile / Library / Mobile% 20Documents / com ~ apple ~ CloudDocs / Documents / Documents% 20-% 20Имя% E2% 80% 99s% 20MacBook% 20Pro /PDF%20Export.compressed.pdf недоступен., NSUnderlyingError = 0x283653300 {Error Domain = NSCocoaErrorDomain Code = 257 "Файл« PDF Export.compressed.pdf »не может быть открыт, так как у вас нет разрешения на его просмотр «. UserInfo = {NSURL = файл: /// частный / вар / мобильная / Библиотека / Мобильный% 20Documents / ком ~ яблочный ~ CloudDocs / Документы / Документы% 20-% 20Name% E2% 80% 99s% 20MacBook% 20Pro / PDF% 20Export .compressed.pdf, NSFilePath = / private / var / mobile / Библиотека / Мобильные документы / com ~ apple ~ CloudDocs / Документы / Документы - MacBook Pro / PDFExport.compressed.pdf, NSUnderlyingError = 0x283653150 {Ошибка домена = Код NSPOSIXErrorDomain = 1 " Операция не разрешена "}}}}

Вот didPickDocumentsAt в моем DocumentPickerViewController

func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
        var userID = profileUID

        let localFile = urls.first!

        let storageRef = Storage.storage().reference()

        // Need to store example.pdf in profiles/userID/documents/example.pdf!!!

        // Upload file and metadata to the object 'images/mountains.jpg'
        let uploadTask = storageRef.putFile(from: localFile, metadata: nil)

        // Listen for state changes, errors, and completion of the upload.
        uploadTask.observe(.resume) { snapshot in
          // Upload resumed, also fires when the upload starts
        }

        uploadTask.observe(.success) { snapshot in
          // Upload completed successfully
            // Set status to complete
        }

        uploadTask.observe(.failure) { snapshot in
            if let error = snapshot.error as NSError? {
                print(error) // This is the only error in the console

            switch (StorageErrorCode(rawValue: error.code)!) {
            case .objectNotFound:
              // File doesn't exist

              break
            case .unauthorized:
              // User doesn't have permission to access file
                print("No permission to access file")

              break
            case .cancelled:
              // User canceled the upload
              break

            case .unknown:
              // Unknown error occurred, inspect the server response
              break
            default:
              // A separate error occurred. This is a good place to retry the upload.
              break
            }
          }
        }

}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...