【问题标题】:Saving a file to .DocumentDirectory using Alamofire使用 Alamofire 将文件保存到 .DocumentDirectory
【发布时间】:2015-03-28 22:14:23
【问题描述】:

我正在尝试下载文件并将其保存到 Documents 目录。我已经在客户端本地完成了这个,没有问题,但是当我在 Alamofire 中使用相同的路径时,我得到了一系列错误。

这是下载组件:

func downloadFileAtIndex(index: Int) {
    Alamofire.download(.GET, "\(serverURL)/user/\(userID)/project/\(arrayOfProjectIDs[index])/deliverable", { (temporaryURL, response) in
        let destinationFolder: String = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String
        let filePath: NSURL = NSURL.fileURLWithPath("\(destinationFolder)/\(arrayOfProjectIDs[index])/myFile.png")!
        return filePath
        })
}

回复是:The operation couldn’t be completed. (Cocoa error 4.)

错误是:The operation couldn’t be completed. No such file or directory.

我知道该目录还不存在,但我想创建它,在本地保存时这似乎不是问题。任何见解将不胜感激。

【问题讨论】:

    标签: ios swift alamofire


    【解决方案1】:

    您的目录不存在。您需要使用NSFileManager 创建它。然后执行下载。

    【讨论】:

      猜你喜欢
      • 2016-04-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-20
      • 1970-01-01
      • 2018-06-24
      • 1970-01-01
      • 2019-04-09
      相关资源
      最近更新 更多