Search code examples
iosasihttprequestfile-type

How to determine what's the file type


I use ASIHTTPRequest to download file. The url is like http://www.aaa.bbb.com:8000/showuploaddocument.aspx?docid=45. So I am not able to determine the file type through the url. How can I determine the file type of the downloaded file?


Solution

  • You can query the Content-Type header returned by the server:

    NSString *contentType = [[request responseHeaders] objectForKey:@"Content-Type"];
    

    This will be a string like image/jpeg, text/plain, etc.