suggestedFilename
Returns a suggested filename for the response data.
- (NSString *)suggestedFilename
Return Value of [NSURLResponse suggestedFilename]
A suggested filename for the response data.
Discussion of [NSURLResponse suggestedFilename]
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.
Example of [NSURLResponse suggestedFilename]
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)aResponse
{
// store the response information
self.response = aResponse;
// Check for bad connection
if ([aResponse expectedContentLength] < 0)
{
NSString *reason = [NSString stringWithFormat:@"Invalid URL [%@]", self.urlString];
DELEGATE_CALLBACK(dataDownloadFailed:, reason);
[connection cancel];
[self cleanup];
return;
}
if ([aResponse suggestedFilename])
DELEGATE_CALLBACK(didReceiveFilename:, [aResponse suggestedFilename]);
}
Example of [NSURLResponse suggestedFilename]
- (NSString *)total {
NSString *responseString = [[NSString alloc] initWithData:urlData encoding:NSASCIIStringEncoding];
NSString *fileName = [response suggestedFilename];
NSLog(@"Value : %@", fileName);
return fileName;
}