Browse files and want to upload on Server

98 Views Asked by At

I am using UIDocumentBrowserViewController to browse the file and getting the URL of the selected file from UIDocumentBrowserViewControllerDelegate method.

 func documentBrowser(_ controller: UIDocumentBrowserViewController, didPickDocumentsAt documentURLs: [URL]) {
        guard let fileUrl = documentURLs.first else { return }
         do {
              let fileData = try Data(contentsOf: fileUrl)
          } catch {
              print(error.localizedDescription)
          }
 }

Now I have to upload this file to our app server, so I am trying to convert it into Data but it's not converting. Getting an error 'The file "File name" couldn’t be opened because there is no such file'.

1

There are 1 best solutions below

0
On

I am using UIDocumentBrowserViewController but it's not working while I am trying to import the document always getting the issue so I use UIDocumentPickerViewController and its working fine for me.