The example for using Alamofire.download() works just fine, but there isn\'t any detail in how to access the resulting downloaded file. I can figure out where the file is and wh
The example on the Alamofire readme file actually has the file path in it, so I grab it with a separate variable to use elsewhere in my code. It is not very elegant and I am hoping there is a way to get that info in the response, but for now, this is getting the job done:
var fileName: String?
var finalPath: NSURL?
Alamofire.download(.GET, urlToCall, { (temporaryURL, response) in
if let directoryURL = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as? NSURL {
fileName = response.suggestedFilename!
finalPath = directoryURL.URLByAppendingPathComponent(fileName!)
return finalPath!
}
return temporaryURL
})
.response { (request, response, data, error) in
if error != nil {
println("REQUEST: \(request)")
println("RESPONSE: \(response)")
}
if finalPath != nil {
doSomethingWithTheFile(finalPath!, fileName: fileName!)
}
}