Difference between Content Type and MIME Type

In day to day, Software Development process we normally encounter with this entity called Content Type and MIME Type. As the name itself sounds, Both defines type of data, that’s simple !! right ?
But have you thought does only purpose this terminologies do have if they both are same. Let’s dig forward about them and see are they really same or serve more purpose than we know,
Take a look at MIME type first,

MIME Type

MIME Type which is known as Multipurpose Internet Mail Extensions type and also called media type generally is a standard that indicates the what kind of a document, file, or stream of bytes. It is refrenced from IETF’s RFC 6838.
Where there are various types data available, to take care of all official MIME Types, The Internet Assigned Numbers Authority (IANA) is responsible which helps us to find the most up-to-date and complete list at their Media Types page.

Syntax

To define MIME type, a type and it’s a subtype which gives exact information when concatenated with forward slash (/) between them, forms a complete MIME type. Just do take care, No whitespaces or tabs are allowed in a MIME Type,
type/subtype
The type denotes the general category into which the data stream belongs, such as image or text. The subtype identifies the exact kind of data of the specified type the MIME type means. For example, for the MIME type text, the subtype might be plain (plain text), html (HTML source code), or calendar (for iCalendar/.ics) files.
Each type has its own set of possible values which are act as subtypes, and a MIME type always has both a type and a subtype, it will never be just one or the other.
An optional parameter can be added to provide additional details:
type/subtype;parameter=value
For example, for any MIME type whose main type is text, the optional charset parameter can be used to specify the character set used for the characters in the data. If no charset is specified, the default is ASCII (US-ASCII) unless overridden by the user agent’s settings. To specify a UTF-8 text file, the MIME type text/plain;charset=UTF-8 is used.
MIME types are case-insensitive but are traditionally written in lowercase, with the exception of parameter values, whose case may or may not have specific meaning.

Type

There are two classes of type: discrete and multipart. Discrete types are types which represent a single file or medium, such as a single text or music file, or a single video. A multipart type is one which represents a document that’s comprised of multiple component parts, each of which may have its own individual MIME type; or, a multipart type may encapsulate multiple files being sent together in one transaction. For example, multipart MIME types are used when attaching multiple files to an email.
Discrete types
The discrete types currently registered with the IANA are:
application
Any kind of binary data that doesn’t fall explicitly into one of the other types; either data that will be executed or interpreted in some way or binary data that requires a specific application or category of application to use. Generic binary data (or binary data whose true type is unknown) is application/octet-stream. Other common examples include application/pdfapplication/pkcs8, and application/zip.
Click here for complete list by IANA.
audio
Audio or music data. Examples include audio/mpeg, audio/vorbis.
Click here for complete list by IANA.
example
Reserved for use as a placeholder in examples showing how to use MIME types. These should never be used outside of sample code listings and documentation. example can also be used as a subtype; for instance, in an example related to working with audio on the web, the MIME type audio/example can be used to indicate that the type is a placeholder and should be replaced with an appropriate one when using the code in the real world.
font
Font/typeface data. Common examples include font/wofffont/ttf, and font/otf.
Click here for complete list by IANA.
image
Image or graphical data including both bitmap and vector still images as well as animated versions of still image formats such as animated GIF or APNG. Common examples are image/jpegimage/png, and image/svg+xml.
Click here for complete list by IANA.
model
Model data for a 3D object or scene. Examples include model/3mf and model/vml.
Click here for complete list by IANA.
text
Text-only data including any human-readable content, source code, or textual data such as comma-separated value (CSV) formatted data. Examples include text/plaintext/csv, and text/html.
Click here for complete list by IANA.
video
Video data or files, such as MP4 movies (video/mp4).
Click here for complete list by IANA.
For text documents without a specific subtype, text/plain should be used. Similarly, for binary documents without a specific or known subtype, application/octet-stream should be used.
Multipart types
Multipart types indicate a category of document broken into pieces, often with different MIME types; they can also be used — especially in email scenarios — to represent multiple, separate files which are all part of the same transaction. They represent a composite document.
With the exception of multipart/form-data, used in the POST method of HTML Forms, and multipart/byteranges, used with 206 Partial Content to send part of a document, HTTP doesn’t handle multipart documents in a special way: the message is transmitted to the browser (which will likely show a “Save As” window if it doesn’t know how to display the document).
There are two multipart types:
message
A message that encapsulates other messages. This can be used, for instance, to represent an email that includes a forwarded message as part of its data, or to allow sending very large messages in chunks as if it were multiple messages. Examples include message/rfc822 (for forwarded or replied-to message quoting) and message/partial to allow breaking a large message into smaller ones automatically to be reassembled by the recipient.
Click here for complete list by IANA.
multipart
Data that is comprised of multiple components which may individually have different MIME types. Examples include multipart/form-data (for data produced using the FormData API) and multipart/byteranges (defined in RFC 7233: 5.4.1 and used with HTTP’s 206 “Partial Content” response returned when the fetched data is only part of the content, such as is delivered using the Range header).
Click here for complete list by IANA.
That’s was all about MIME type and it’s sub-type, Now Let’s see what Content Type really means,

Content Type

The Content-Type is the header parameter we set to indicate what kind of data is being pushed in HTTP request. also in HTTP responses, a Content-Type header tells to the client (which may be browser, mobile or any device) what actual type of contents are received by them.
Browsers will do MIME sniffing in some cases and will not necessarily follow the value of this header. For example, In response IMAGE contents are being returned, Browser display what actual image is. To prevent this behavior, the header X-Content-Type-Options can be set to nosniff.
In HTTP requests, (such as POST or PUT), the client is able to tell the server what type of data is actually going to sent.

Syntax

Content-Type: media-type; charset=encoding; boundary=some information
Let’s take brief on the values and their responsibility
media-type
The MIME type of the resource or the data.
charset
The character encoding standard.
boundary
For multipart entities the boundary directive is required, which consists of 1 to 70 characters from a set of characters known to be very robust through email gateways, and not ending with white space. It is used to encapsulate the boundaries of the multiple parts of the message. Often, the header boundary is prepended with two dashes and the final boundary has two dashes appended at the end.

Example

Content-Type: text/html; charset=UTF-8
Content-Type: multipart/form-data; boundary=---------------------------974767299852498929531610575
-----------------------------974767299852498929531610575
Hence we can say Content Type and MIME type work really close together describing content, and are a lot helpful than we think. :)
Let me know your views in comments,

Comments

Popular posts from this blog

Hello World !!!

After a long while... Let's start !!