Created
July 7, 2014 02:34
-
-
Save dduan/2ecc257ab908aff24530 to your computer and use it in GitHub Desktop.
Guessing MIME type from a file name in Objective-C on iOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSString *)guessMIMETypeFromFileName: (NSString *)fileName { | |
// Borrowed from http://stackoverflow.com/questions/2439020/wheres-the-iphone-mime-type-database | |
CFStringRef UTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)[fileName pathExtension], NULL); | |
CFStringRef MIMEType = UTTypeCopyPreferredTagWithClass(UTI, kUTTagClassMIMEType); | |
CFRelease(UTI); | |
if (!MIMEType) { | |
return @"application/octet-stream"; | |
} | |
return (__bridge NSString *)(MIMEType); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment