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://allsee
In the NSURLConnection delegate callback - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
you can retrieve the suggestedFileName
from the NSURLResponse. 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.
suggestedFilename
Returns a suggested filename for the response data.
- (NSString *)suggestedFilename
Return Value
A suggested filename for the response data.
Discussion
The method tries to create a filename using the following, in order:
A filename specified using the content disposition header.
The last path component of the URL.
The host of the URL.
If the host of URL can't be converted to a valid filename, the filename “unknown” is used.
In most cases, this method appends the proper file extension based on the MIME type. This method will always return a valid filename regardless of whether or not the resource is saved to disk.
Availability
Available in iOS 2.0 and later. Declared In NSURLResponse.h