2016-10-27 238 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下載請求。感謝您的時間和評論。