【问题标题】:Browse files and want to upload on Server浏览文件并想上传到服务器
【发布时间】:2020-06-20 02:07:23
【问题描述】:

我正在使用 UIDocumentBrowserViewController 浏览文件并从 UIDocumentBrowserViewControllerDelegate 方法获取所选文件的 URL。

 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)
          }
 }

现在我必须将此文件上传到我们的应用服务器,所以我试图将其转换为数据,但它没有转换。收到错误“无法打开文件“文件名”,因为没有这样的文件”。

【问题讨论】:

  • 它是否超过了您的guard?它打印什么吗?
  • @PhillipMills 是的,我能够获取 URL,但无法将其转换为数据

标签: ios swift uidocumentbrowserviewcontroller


【解决方案1】:

我正在使用 UIDocumentBrowserViewController,但在我尝试导入文档时它无法正常工作,所以我使用 UIDocumentPickerViewController 并且它对我来说工作正常。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-09-11
    • 2013-04-26
    • 2011-11-04
    • 2022-07-21
    • 2012-02-22
    • 2023-03-23
    • 1970-01-01
    相关资源
    最近更新 更多