什么是MIME
MIME type的縮寫(xiě)為(Multipurpose Internet Mail Extensions)代表互聯(lián)網(wǎng)媒體類(lèi)型(Internet media type),MIME使用一個(gè)簡(jiǎn)單的字符串組成,最初是為了標(biāo)識(shí)郵件Email附件的類(lèi)型,在html文件中可以使用content-type屬性表示,描述了文件類(lèi)型的互聯(lián)網(wǎng)標(biāo)準(zhǔn)。MIME 消息能包含文本、圖像、音頻、視頻以及其他應(yīng)用程序?qū)S玫臄?shù)據(jù)。
- 獲取某一個(gè)文件的響應(yīng)頭信息(MIMEtype)的方法
mimeTypeForFileAtPath:
NSString * type = [self mimeTypeForFileAtPath:@"/Users/mario/Desktop/截圖文件夾/iconView/Snip20160518_3.png"];
NSLog(@"%@",type);
- 獲取MOMEType的四種方法
- 方法一:通過(guò)對(duì)文件發(fā)送請(qǐng)求,得到響應(yīng)頭信息的MIMEType
-(void)getMEMIType1
{
NSURL * url = [NSURL fileURLWithPath:@"/Users/mario/Desktop/截圖文件夾/iconView/Snip20160518_3.png"];
[[[NSURLSession sharedSession] dataTaskWithURL:url completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
NSLog(@"%@",response.MIMEType);
}] resume];
}
- 方法二:通過(guò)C語(yǔ)言的API
-(NSString *)mimeTypeForFileAtPath:(NSString *)path
{
if (![[[NSFileManager alloc] init] fileExistsAtPath:path]) {
return nil;
}
CFStringRef UTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)[path pathExtension], NULL);
CFStringRef MIMEType = UTTypeCopyPreferredTagWithClass (UTI, kUTTagClassMIMEType);
CFRelease(UTI);
if (!MIMEType) {
return @"application/octet-stream";
}
return (__bridge NSString *)(MIMEType);
}
- 方法三:通過(guò)百度查詢(xún)MIMEType
- 方法四:通用的二進(jìn)制數(shù)據(jù)類(lèi)型 任意的二進(jìn)制數(shù)據(jù) application/octet-stream