Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get filename from NSURLSession download

I'm using NSURLSession to download file. Some websites (like Amazon) don't use filenames in URL (like: http://server/file.php?id=22). How can I get that filenames?

Example URL without name: https://odesk-prod-att.s3.amazonaws.com/...oCtjM%3D

I'm using such function:

func URLSession(session: NSURLSession, downloadTask: NSURLSessionDownloadTask, didFinishDownloadingToURL location: NSURL) {
    print("Download finished: \(location.absoluteString)")
}

// Download finished: file:///.../CFNetworkDownload_UTywas.tmp
like image 484
Vasily Avatar asked Feb 10 '16 15:02

Vasily


1 Answers

Check for the suggested filename before creating your own:

downloadTask.response?.suggestedFilename
like image 122
emp Avatar answered Oct 04 '22 23:10

emp