Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to upload document using documentpicker. I am able to browse the document from my phone document folder but after choosing nothing is happen. I want to get that document like (sample.text or sample.pdf) and upload it to my database server.

Here is my code:

@IBAction func bio_choose_document_btn(_ sender: Any) 
   {

        let importDocument = UIDocumentPickerViewController(documentTypes: [String(kUTTypePDF), String(kUTTypePlainText), String(kUTTypeJPEG), String(kUTTypePNG)], in: .import)
        importDocument.delegate = self
        importDocument.allowsMultipleSelection = true
        importDocument.modalPresentationStyle = .formSheet
        self.present(importDocument, animated: true, completion: nil)
    }
    
    public func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
        guard let filepathurl = urls.first
            else {
            return
        }
        let fileName = filepathurl.lastPathComponent
        bio_no_file_choosen_lbl.text = fileName
        
        doc_webview.load(URLRequest(url: filepathurl))
        //let items = TableViewItem()
        //items?.documentname = self.bio_doc_view.text
        //self.TableView_item.append(items!)
        print("import result : (filepathurl)")
        self.bio_documentview_tvc.reloadData()
    }
    
          

    public func documentMenu(_ documentMenu:UIDocumentPickerViewController, didPickDocumentPicker documentPicker: UIDocumentPickerViewController) {
        documentPicker.delegate = self
        present(documentPicker, animated: true, completion: nil)
    }


    func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {
        print("view was cancelled")
        dismiss(animated: true, completion: nil)
    }

I am using webview but it opens the whole document as a view. I don't want to open it. I want to retrieve the document as a folder.

Any help will be highly appreciated.
Thank You!
Rutuparna Panda

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
114 views
Welcome To Ask or Share your Answers For Others

1 Answer

Typically, you get the file path (URL) of the local file and then upload the file through the file path (URL).

AFN/Alamofire Post

  //...
  do{
      try formData.appendPart(withFileURL: filepathurl, name: "file")
  } catch {
      DDLog("error:(error.localizedDescription)")
  }
  //"file" is a field that is agreed with a server colleague
  //...

github


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...