Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert mimetype to file extension

how to convert mimetype to file extension in xcode for example i have this code

File Extension     MIME Type

aifc                audio/x-aiff
avi                 video/x-msvideo
gz                  application/x-gzip
jpg                 image/jpeg

Xcode

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
        NSString *mime      = [response MIMEType];
        NSString *extension = @"" // how to covert it ?!
}
like image 948
Fawaz Avatar asked Jul 10 '14 14:07

Fawaz


People also ask

What is the MIME type of a file?

A media type (also known as a MIME type) is a two-part identifier for file formats and format contents transmitted on the Internet. The Internet Assigned Numbers Authority (IANA) is the official authority for the standardization and publication of these classifications.

What is the MIME type for PDF?

The main MIME media type for PDF is application/pdf. This type is defined by RFC 8118 and is the responsibility of ISO TC 171 SC 2 WG 8. It was last updated in March 2017, prior to the original publication of PDF 2.0, so the PDF Association is proposing a minor refresh and update in the upcoming May 2022 ISO meetings.

Is MIME type same as file type?

Slightly longer answer: Mime types and file extensions provide hints to how to deal with a file. Whereas file extensions are commonly used for your OS to decide what program to open a file with, Mime types are used by your browser to decide how to present some data (or the server on how to interpret received data).


1 Answers

include <MobileCoreServices/MobileCoreServices.h> or <CoreServices/CoreServices.h> then just following code:

CFStringRef mimeType = (CFStringRef)@"audio/x-aiff";
CFStringRef uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, mimeType, NULL);
CFStringRef extension = UTTypeCopyPreferredTagWithClass(uti, kUTTagClassFilenameExtension);
like image 83
Watsche Avatar answered Sep 30 '22 10:09

Watsche