1
我想用alamofire从swift下载PDF文件,它显示损坏的文件。为了安全起见,我需要添加一些额外的参数。从url下载pdf文件
这是我的网址格式。
当我尝试在浏览器中粘贴此URL时,它从url下载PDF。但是当我尝试使用Alamofire在Swift中从url下载pdf时,它存储了一些随机字节数据。但没有PDF文件。当我尝试打开pdf时,它显示文件已损坏。
这是我的Alamofire代码。
let destination = Alamofire.Request.suggestedDownloadDestination(directory: .ApplicationSupportDirectory, domain: .UserDomainMask)
Alamofire.download(.GET, url!, destination: destination).progress({ (bytesRead, totalBytesRead, totalBytesExpectedToRead) in
print(totalBytesRead)
// This closure is NOT called on the main queue for performance
// reasons. To update your ui, dispatch to the main queue.
dispatch_async(dispatch_get_main_queue()) {
print("Total bytes read on main queue: \(totalBytesRead)")
}
}).response(completionHandler: { (request, response, data, error) in
if let error = error {
print("Failed with error: \(error)")
} else {
print("Downloaded file successfully")
}
})
请帮我解决。 在此先感谢。
链接已损坏。 [证明](http://imgur.com/a/pN1hm) – eshirima
如果链接被破坏,为什么它应该在浏览器上运行? – VDPATEL
链接已损坏。 – Ujwal