繁体   English   中英

从网址下载pdf文件

[英]Download pdf file from url

我试图使用Alamofire快速从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")
        }
    })

请帮我解决。 提前致谢 。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM