Uploading Documents (.png, .jpeg, .jpg, .pdf) using iOS app and save them on backend

Hi,We had the requirement to upload documents (.pdf, .jpeg, .png, .jpg) from our iOS app and send it to our backend. I tried to do it using UIDocumentPickerViewController. After clicking on the button to upload, Files folder of iPhone opens, but all the data in it appears to be disabled. I am not able to select any document and upload it. Can some please help me with what can be the better options, which can be used?

I tried to do a lot R&D but was not able to get some good options.

Replies

Do you succeed in loading the document in your app, first ?


Can you show the code where you try to get and upload document ?


That should be possible :

Document Picker Modes

The document picker supports four modes. Each mode provides a slightly different approach to sharing files between apps.

  • Import an external document. The user selects an external document. The document picker copies the document, leaving the original unchanged.
  • Export a local document. The user selects an external destination. The document picker copies the document, leaving the original unchanged.
  • Open an external document. The user selects an external document. The document picker provides access to the document, and the user can edit the document in place.
  • Move a local document. The user selects an external destination. The document picker moves the document; however, the user can still access the document as an external document, and the user can edit the document in place.

Hi Claude31,


I am sharing the code with I am using for Document picker.

let picker = UIDocumentPickerViewController.init(documentTypes: [".pdf", ".png", ".jpeg", ".jpg"], in: .open)

let picker = UIDocumentPickerViewController(documentTypes: ["public.pdf"], in: .open)

picker.delegate = self

picker.modalPresentationStyle = .fullScreen

self.present(picker, animated: true, completion: nil)

Even one more issue is occuring:


let icloudFolderURL:- FileManager.default.url(forUbiquityContainerIdentifier: nil)?.appendingPathComponent("Documents").


icloudFolderURL returns nil to me.

As far as I know, file extensions (.pdf, .jpeg, .png, .jpg) or public.pdf are not valid UTIspassed to `documentTypes`.


With `import CoreServices`, you can use some constant symbols like this:

let picker = UIDocumentPickerViewController(documentTypes: [kUTTypePDF as String, kUTTypePNG as String, kUTTypeJPEG as String], in: .open)