Ios 浏览文件并希望上载到服务器上
我正在使用UIDocumentBrowserViewController浏览文件,并从UIDocumentBrowserViewControllerDelegate方法获取所选文件的URLIos 浏览文件并希望上载到服务器上,ios,swift,uidocumentbrowserviewcontroller,Ios,Swift,Uidocumentbrowserviewcontroller,我正在使用UIDocumentBrowserViewController浏览文件,并从UIDocumentBrowserViewControllerDelegate方法获取所选文件的URL func documentBrowser(_ controller: UIDocumentBrowserViewController, didPickDocumentsAt documentURLs: [URL]) { guard let fileUrl = documentURLs.fir
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)
}
}
现在我必须把这个文件上传到我们的应用服务器上,所以我试图把它转换成数据,但它没有转换。出现错误“文件名无法打开,因为没有这样的文件”。我使用的是UIDocumentBrowserViewController,但在我尝试导入文档时它不起作用。总是会遇到问题,所以我使用UIDocumentPickerViewController,它对我来说可以正常工作。它能让你放心吗?它会打印什么吗?@PhillipMills是的,我可以获取URL,但无法将其转换为数据