【发布时间】:2019-07-25 06:39:21
【问题描述】:
首先,使用 Alamofire 从 URL 成功下载后,我将文件扩展名更改为 .ZIP,然后在解压缩时出错。 没有得到预期的文件。
let destination = DownloadRequest.suggestedDownloadDestination(for: .documentDirectory)
Alamofire.download(fileURL!, method: .get, parameters: nil, encoding: JSONEncoding.default, headers: headers, to: destination).downloadProgress(closure: { (progress) in
print(progress.completedUnitCount)
}).responseData { (responce) in
let destiUrl = responce.destinationURL
print(destiUrl!)
let newUrl = destiUrl?.deletingPathExtension().appendingPathExtension("zip")
do {
try FileManager.default.copyItem(at: destiUrl!, to: newUrl!)
let unzipDirectory = try Zip.quickUnzipFile(newUrl!)
print(unzipDirectory.absoluteString)
}
catch let error as NSError{
print(error)
}
}
下载成功后的文件地址-->
file:///var/mobile/Containers/Data/Application/9D96958C-903E-4693-9965-6FB919BB24F1/Documents/'87dc4a8ddce24cf9ad35a251d6a98195.hub'
转换为 .zip 后的文件 URL
file:///var/mobile/Containers/Data/Application/9D96958C-903E-4693-9965-6FB919BB24F1/Documents/'87dc4a8ddce24cf9ad35a251d6a98195.zip
解压后的最终网址
file:///var/mobile/Containers/Data/Application/9D96958C-903E-4693-9965-6FB919BB24F1/Documents/'87dc4a8ddce24cf9ad35a251d6a98195/
实际结果应该是音频文件。
【问题讨论】:
-
您不能只是将文件扩展名更改为 zip 并期望它是 zip 存档。
-
下载的文件是一个zip压缩包,出于安全原因,文件扩展名是从后端更改的。如果您没有收到问题,请不要标记为否定。
-
解压时出现什么错误?
-
解压后请查看最终网址