【问题标题】:File name that saved in document directory have space character保存在文档目录中的文件名有空格字符
【发布时间】:2018-05-30 21:30:40
【问题描述】:

我想下载视频文件并将其保存在 文档目录,但是当我尝试显示下载的视频时,我无法创建该文件的 URL。 我正在使用此代码为保存文件创建路径。我的文件名有空格:(mobileslider video.mp4),我想用自己的名字保存这个视频,但我无法创建包含空格的 url 路径。如何解决这个问题?

如果让 url = URL(string:videoURL){

showVideoFromNib(nibURL:url)

}

当我尝试从 videoURL 中删除空间时,调用 showVideoFromNib 方法但不显示视频。当使用原始 url 时,showVideoFromNib 方法没有调用。

编辑 1:

我更改目标路径

 let destination = DownloadRequest.suggestedDownloadDestination(for: .documentDirectory)

 let destination: DownloadRequest.DownloadFileDestination = { _, _ in
      let pathComponent = "pack\(self.packID)-\(selectRow + 1).mp4"
      let directoryURL: URL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
      let folderPath: URL = directoryURL.appendingPathComponent("Downloads", isDirectory: true)
      let fileURL: URL = folderPath.appendingPathComponent(pathComponent)
      return (fileURL, [.removePreviousFile, .createIntermediateDirectories])
    }

现在我可以创建 URL 和我的显示视频方法调用,但视频不显示。 这是我的新示例路径:

/Users/MyUser/Library/Developer/CoreSimulator/Devices/2C2B6A39-5426-4E2C-B25A-CF64817AF26F/data/Containers/Data/Application/5A1BB109-D452-4F03-8820-EE1120E07C3D/Documents/Downloads/pack7- 2.mp4

此路径中存在此文件,但视频播放器不显示此文件。

【问题讨论】:

    标签: ios swift url filepath


    【解决方案1】:

    我解决问题。我正在使用

    let path = destinationUrl.absoluteString
    

    而不是

    let path = destinationUrl.path
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-17
      • 2018-10-10
      • 1970-01-01
      • 2017-11-22
      • 2014-09-10
      • 1970-01-01
      • 1970-01-01
      • 2011-09-23
      相关资源
      最近更新 更多