I was wondering on how to download a file using NSUrl where the filename is not available or is not part of the request URL. I have been looking at ASIHTTPRequest (http://allseeing-i.com/ASIHTTPRequest/) library. It has
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDownloadDestinationPath:@"/Users/ben/Desktop/my_file.txt"];
But the point is you need to know the file name here. For example if you put the URL (not real URL) http://some-website/foo.pdf
It downloads a file foo.pdf and I want to save it like that. Any ideas thanks.
Best Answer
In the NSURLConnection delegate callback
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
you can retrieve thesuggestedFileName
from theNSURLResponse
. If you get unknown for a name then you need to come up with another name for your file. At this point you can specify your download path before you start saving data.