2016-10-27 239 views
1

我想用alamofire从swift下载PDF文件,它显示损坏的文件。为了安全起见,我需要添加一些额外的参数。从url下载pdf文件

这是我的网址格式。

https://xyz.xom/123/PDF_1477.pdf?sv=2015-04-05&sr=b&sig=asasasasakskasajsa%3D&se=2016-10-26T18%3A34%3A21Z&sp=r

当我尝试在浏览器中粘贴此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") 
     } 
    }) 

请帮我解决。 在此先感谢。

+0

链接已损坏。 [证明](http://imgur.com/a/pN1hm) – eshirima

+0

如果链接被破坏,为什么它应该在浏览器上运行? – VDPATEL

+0

链接已损坏。 – Ujwal

回答

2

我的问题现在解决了。我已经删除了我的PDF网址的网址编码,并将编码传递给Almofire下载请求。感谢您的时间和评论。