【发布时间】:2021-07-01 17:20:30
【问题描述】:
我正在尝试使用 documentpicker 上传文档。我可以从我的手机文档文件夹中浏览文档,但选择后什么也没有发生。我想获取该文档(例如(sample.text 或 sample.pdf)并将其上传到我的数据库服务器。
这是我的代码:
@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)
}
我正在使用 webview,但它会将整个文档作为视图打开。我不想打开它。我想将文档作为文件夹检索。
任何帮助将不胜感激。
谢谢!
鲁图帕纳熊猫
【问题讨论】:
标签: swift