JavaScript/AJAX code for Mime Type Example
This JavaScript/AJAX code snippet was generated automatically for the Mime Type example.<< Back to the Mime Type example
What is MIME Type?
MIME stands for Multipurpose Internet Mail Extensions.It is a fundamental part of communication protocols such as HTTP. The MIME type is required when you need to transfer non-text data. MIME was originally designed to extend the capabilities of email to support more data types such as non-ASCII text files and binary files such as images, PDFs, and executables. The use of MIME is not limited to email. It is now actively used in all communications over the Internet to describe the type of data sent to or from a server. It is often referred to as a media type or MIME content type. In HTTP, the MIME-type is part of the Content-Type header of an HTTP message and defines the data type in the body of an HTTP request or response. Setting the correct MIME data type in the body of the message is critical for both HTTP requests and responses and allows you to control how the request is interpreted by the client and server. Web servers and browsers have a list of well-known file extensions and MIME types. This helps them identify and interpret all known file types, regardless of the operating system and hardware used by the user.
What is the MIME structure?
MIME types usually consist of three parts: type, subtype, and optional parameters, separated by a forward slash "/" without spaces. The MIME type is not case-sensitive but is usually written in lowercase letters. A MIME type must have a type as well as a subtype. Each type has its own set of possible subtypes. For example, text/plain; charset=UTF-8 describes data in plain text format with UTF-8 encoding. The following is an example of the MIME type of an HTTP request:
The following is an example of the MIME type of an HTTP response
How to pass multiple objects in a single MIME message?
The MIME format supports the transmission of multiple objects in one message. Entities can be transferred not only in the form of a single-level sequence but also in the form of a hierarchy with the nesting of elements into each other. The multipart/* media type is used to indicate multiple contents. To transmit a multipart message, a boundary parameter is added to the Content-Type header, which denotes the sequence of characters that separate the parts of the message. The border can consist of numbers, letters, and symbols () + _, -. /: = ?.
The beginning of each part of the message is indicated by the string --boundary. The end of the last message is indicated by the string --boundary--. At the very beginning of the included part, there are headers that describe its content (Content-Type, Content-Length, etc.). If Content-Type is not specified, then text/plain is used by default.
Common MIME Types
The IANA is the official registry of MIME media types and maintains a list of all known official MIME types. Below is a short list of popular MIME types for the Internet.
- Images: image/jpeg, image/png, image/gif, image/svg+xml
- Files: text/plain, application/pdf, application/zip
- Applications: application/octet-stream, application/pkcs8
- Media: audio/mpeg, video/mp4, video/mpeg
- Data: application/json, application/xml