To download for Swift 2.x users using Alamofire> = 3.0:
let url = "https://httpbin.org/stream/100" // this is for example.. let destination = Alamofire.Request.suggestedDownloadDestination(directory: .DocumentDirectory, domain: .UserDomainMask) Alamofire.download(.GET, url, parameters: params, encoding: ParameterEncoding.URL,destination:destination) .progress { bytesRead, totalBytesRead, totalBytesExpectedToRead in // 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()) { // Here you can update your progress object print("Total bytes read on main queue: \(totalBytesRead)") print("Progress on main queue: \(Float(totalBytesRead) / Float(totalBytesExpectedToRead))") } } .response { request, _, _, error in print("\(request?.URL)") // original URL request if let error = error { let httpError: NSError = error let statusCode = httpError.code } else { //no errors let filePath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] print("File downloaded successfully: \(filePath)") } }
source share