Skip to main content.

Web Based Programming Tutorials

Homepage | Forum - Join the forum to discuss anything related to programming! | Programming Resources

Web Database Developer's Guide with Visual Basic 5

World Wide Web Database Developer's Guide with Visual Basic 5





-G-

An Overview of MIME

This appendix provides an overview of MIME data types: what they are, how they are used, and their increasing importance in Web-based multimedia applications--including the presentation of information resulting from a database query. Anyone who wants to develop Web applications that will provide more than just text-based functionality should have at lease some knowledge of MIME. In fact, HTML is a fundamental MIME data type; without it, most of today's Web applications would not be possible.

What Is MIME?

It's not a stretch to say that without the MIME standard, many of today's Web applications would not exist as we know them. HTML is well known among Web application developers, but how many developers are aware that HTML is a MIME data type? But MIME doesn't stop there--it defines a (growing) set of data types that enable you to create Web applications, such as the results of database queries, that incorporate multimedia components such as audio, video, and animated graphics.

Multipurpose Internet Mail Extensions (MIME) is a newer Internet mail standard that builds on and greatly extends the functionality of the earlier e-mail standards (primarily RFC 821 and RFC 822). MIME specifies how to send multipart, multimedia, and binary data over the Internet.

Some of the new capabilities of e-mail that MIME extensions provide follow:

MIME messages can handle a variety of data types used on the Internet, because MIME replaces previous encoding methods (including uuencode) with an encoding method called Base-64. This method is more robust and is not subject to the limitations and interoperability problems that other encoding mechanisms present.

The MIME standard is defined in large part by the Internet standards documents RFC 1521 and RFC 1522.

MIME Uses

There are many obvious uses for MIME, including sending images, word processing documents, audio or video clips, binary executable programs, and even plain ASCII text (yes, you still can do the simple stuff) as part of your e-mail. These are common functions allowed by most of today's newer e-mail systems.

What might not be so obvious is the functionality that MIME brings to CGI programs used to create on-the-fly data presentations and to format output of database processing performed by a Web server on behalf of a Web client. In fact, the very creation of HTML documents that a client browser can render depends on the use of MIME. Remember from Chapter 18, "The Common Gateway Interface (CGI)," that if data is to be returned to a Web client by a CGI program, the data must be prefaced by this MIME Content-type data header:

Content-type: text/html

You also can use MIME data types to spice up HTML documents and presentations by allowing links to multimedia components such as graphics, images, audio, video, and server-push animation. You use these types not simply to make the presentations nicer, but also to extend the functionality of the applications and to add value for your users.

Many of your readers who enjoy surfing the Net have experienced MIME without even realizing it. Many sites now incorporate links to audio and video clips to enhance their documents. Figure G.1 shows part of the United States Department of State's Heroes page.

FIGURE G.1.Using audio and video MIME data types.


RESOURCE: The United States Department of State's Heroes page is a nice example of how you can incorporate audio and video into an HTML document. You can find it at this URL:
http://www.heroes.net/pub/heroe 



The HTML code to generate the links in this example follows:

<IMG SRC="http://www.heroes.net/pub/heroes/gifs/heston.gif" ALIGN="MIDDLE">

<B>Charlton Heston  </B>

<A HREF="http://www.heroes.net/pub/heroes/wavs/heston.wav">

<IMG SRC="http://www.heroes.net/pub/heroes/gifs/audio.gif" ALIGN="MIDDLE"></A>

<A HREF="http://www.heroes.net/pub/heroes/avis/heston1.avi">

<IMG SRC="http://www.heroes.net/pub/heroes/gifs/video.gif" ALIGN="MIDDLE"></A>

This example illustrates how easy it is to incorporate multimedia components and MIME data types into data presentations. The small GIF images of an audio speaker and video camera are used as hypertext links and provide visual cues to the user that audio or video data is available by clicking those links. The links are used to point to video data (heston.wav) and audio data (heston1.avi). The heston.wav file is a MIME file of type audio/x-wav, which means that it is audio data of the experimental subtype (format) x-wav. The heston.avi file is a MIME file of type video/x-msvideo, which means that it is video data of the experimental subtype (format) x-msvideo.

MIME Content Types and Subtypes

The MIME standard defines a number of new header fields, one of which is the Content-type header field. This header field specifies the type and subtype of data in the body of a message, as well as the encoding of that data. The syntax for a Content-type header field follows:

Content-Type := type "/" subtype [";" parameters]...

Here, type declares the type of data, subtype specifies a specific format for that data type, and parameters modifies the content subtype. Note that each type must be specified with a subtype.


RESOURCE: You can get an up-to-date list of registered MIME types and subtypes, including a complete list of the latest application subtypes, at
ftp://ftp.isi.edu/in-notes/iana/assignments/media-types/media-types


This site contains comprehensive information and references about each registered type. You can reference documents related to specific media types by specifying the type and subtype, as shown here:

.../media-types/type

.../media-types/type/subtype

You would use the following URL, for example, to get information about the msword MIME application subtype:

ftp://ftp.isi.edu/in-notes/iana/assignments/media-types/application/msword

Content-Types

Table G.1 lists the seven primary Content-type header fields specified by the MIME standard. These types are discussed in more detail later in this section.

Table G.1. Content-type Header Fields.

Content-type Function
application Transmits application data or binary data that does not fit other MIME type categories
audio Transmits voice or audio data
image Transmits image data (such as GIF or JPEG)
message Encapsulates mail messages
multipart Composes and transmits messages consisting of more than one body part (these body parts can consist of different data types)
text Sends textual information
video Transmits video data and possibly integrated sound data


Application Content-type
You use Application Content-type to send data that does not fit into the other Content-type categories. This can include uninterpreted binary data. Currently, nearly 40 valid subtypes exist. This list is growing steadily as vendors continue to register types specific to their applications. Here is a representative sample of subtypes:

The following example shows how to specify an Application Content-type header indicating that the message body contains a PostScript document:

Content-type: application/postscript

Audio Content-type You use Audio Content-type for audio data. The receiving user or application must have adequate capabilities for interpreting the audio format and outputting the sound. Valid subtypes follow:

The following example shows how to specify an Audio Content-type header indicating that the audio data is in basic (8-bit ISDN u-law encoding; 8000Hz, single-channel) format:

Content-type: audio/basic

Image Content-type You use Image Content-type for image data. The receiving user or application must have adequate capabilities for interpreting the image format and displaying the data. Valid subtypes follow:

The following example shows how to specify an Image Content-type header indicating that the image data is in JPEG format:

Content-type: image/jpeg

Message Content-type You use Message Content-type to send messages that are encapsulated. These messages also can be partial or just a reference to an external message body. Valid subtypes follow:

The following example shows how to specify a Message Content-type header indicating that the message body is encapsulated and uses the syntax of an RFC 822 message:

Content-type: message/rfc822

Multipart Content-type You use Multipart Content-type to send messages that consist of multiple body parts, each with its own data type. Valid subtypes follow:

Special strings called encapsulation and closing boundaries are used to indicate where body parts begin and end, as well as where the final body part in the message ends. These strings are indicated by a mandatory parameter named boundary. Any information before the first encapsulation boundary (often called the preamble) or after the closing boundary (often called the epilogue) is ignored.

An encapsulation boundary is an end-of-line (EOL), followed by two hyphens, followed by the boundary string. The closing boundary is an EOL, followed by two hyphens, the boundary string, and two more hyphens. A multipart message, for example, might have a Content-type header such as this:

Content-type: multipart/mixed; boundary="abcdefg"

In this case, the encapsulation boundary would be

--abcdefg

whereas the closing boundary would be

--abcdefg--

Here is an example of a multipart message that includes both plain text and GIF image body parts:

Content-type: multipart/mixed; boundary="MSGBOUNDARY"

--MSGBOUNDARY

Content-type: text/plain

...text...
...text...

--MSGBOUNDARY

Content-type: image/gif

...GIF Image Data...
...GIF Image Data...

--MSGBOUNDARY--

Text Content-type You use Text Content-type to send messages that are primarily textual. It is the default MIME Content-type. Valid subtypes follow:

You also can specify a Charset parameter to indicate the text's character set. Here is an example of how to specify a Text Content-type header:

Content-type: text/plain; Charset=US-ASCII

Video Content-type You use Video Content-type for video data. Video is a generic term that can include any image or graphical data that changes with time. This data can be black and white, gray-scale, or color. Also, it can be coordinated with sound. Video data requires the receiving user or application to have adequate capabilities for interpreting the video format and displaying the data. Valid subtypes follow:

The following example shows how to specify a Video Content-type header indicating that the video data is in MPEG format:

Content-type: video/mpeg

Experimental and Private MIME Types

In addition to seven primary Content-type header fields and their respective subtypes, the MIME standard supports private or experimental types, subtypes, and parameters. These typically are enumerated by an x- prefix. This example specifies FrameMaker documents, for example:

application/x-framemaker

CAUTION: The meanings of these types, subtypes, and parameters depend on agreements between the senders and receivers of such data. Both sides must know and agree on the interpretation. The list of these types is growing daily. Just because an x-type or x-subtype exists, however, does not mean that any standardization exists or that a particular type is a registered type. Note also that several experimental or private types exist that have foregone the use of the "required" x- prefix in their names.

MIME Extensibility

One of the MIME standard's major strengths is its extensibility. The creators of the standard expected that the set of Content-type/subtype pairs (and their parameters) would grow with time. To ensure orderly growth, the MIME standard defines a registration process by which creators of MIME types or subtypes can register these types. The process uses the Internet Assigned Numbers Authority as a central registry for these numbers. Note that as more vendors and organizations develop Web-enabled applications, the number of registered types is expected to grow considerably.

So Why Is This MIME Stuff Important?

So what does MIME have to do with developing Internet applications? MIME standards play a role in virtually all data transactions on the Internet and intranets. Having some knowledge of MIME standards and MIME media types is important for both users and developers.

The Users Perspective

Multimedia is quickly becoming commonplace on desktop computing platforms. It's difficult to buy systems that don't support some form of audio output and video display. Also, more and more Web sites are incorporating audio and video into their HTML presentations. This trend is expected to increase.

Web users therefore must have some knowledge of MIME media types so that they can configure their Web browsers to take advantage of the more common multimedia components served by Web sites. An increasing number of Web sites are developing and serving non-standard and experimental MIME types, and many of them provide downloadable plug-ins or helper applications that understand how to interpret and render the non-standard MIME data types.

Helper applications and plug-ins are programs invoked by Web browsers in response to receiving data of various MIME types. Many browsers--such as Netscape, Internet Explorer, and Mosaic--come with helper and plug-in applications that are preconfigured for common data types such as GIF and JPEG images. Other helper applications must be configured by the user in order to properly handle some MIME types. Using Netscape to handle audio data of MIME type audio/x-wav (WAV format files), for example, requires the user to specify an application to invoke when this data type is received by the browser. The same is true for video data of MIME type video/x-msvideo (such as AVI format files).

Under Netscape, you can configure helper applications by choosing Options | General Preferences and then selecting the Helpers tab, as shown in Figure G.2.

You can configure other major browsers by using similar methods.

Figure G.2 indicates that files of MIME type audio/x-wav should be handled using the Mplayer application under Windows 95. Note that other MIME types such as video/mpeg are set to prompt the user for action instead of launching an application. Users can change this setting if a suitable MPEG player application is available.

On an increasing number of Websites, vendors or individuals who have implemented less- common or non-standard MIME types will provide downloadable plug-in applications for handling their data.

FIGURE G.2.Setting up Netscape helper applications to use MIME data types.


CAUTION: As with any software, especially freeware, make sure that you are confident of the integrity of the site from which you are downloading a plug-in application. Virus-infected software and poorly designed applications can wreak havoc on your system.

The Developers Perspective

The most important thing you can do as a developer is to create applications that serve the needs of your users. As the world of computing continues to embrace multimedia applications, it's no longer sufficient to provide primarily text-based data presentations. Of course, I'm not saying that using text is unimportant or trying to discourage you from using it; I'm just pointing out that users respond to applications that take advantage of audio and video, as well as the newer media types and applications. To adequately address your users' needs and desires, you must maintain an awareness of MIME and keep abreast of the new data and application types being introduced.

You also must be aware of MIME media types when integrating applications into your CGI programs. Graphics, server-push animation, video, audio, 2D and 3D charts, plots and graphs, and other means of visualizing data are increasingly being integrated into CGI applications. In some cases, this requires that you use registered, standard MIME types; in other cases, you may need to use (or define) non-standard types. Integrating a VRML application with your CGI applications, for example, would require you to use a non-standard type such as this:

Content-type: x-world/x-vrml

Finally, when using MIME types that require a user to configure a helper application on his browser, you should give him some indication, via text or an icon, that a certain MIME type will be sent to the browser. This indication enables the user to properly configure his browser with a helper application or to download a plug-in application, if available, from the site.

MIME References

Information on MIME is available from a variety of sites on the Web. Using your favorite search engine, you can find several good starting points. Additionally, the URLs listed in the following resource point to the original Internet Mail standards documents, MIME FAQs, sites for MIME standards documents, and some MIME overview documents.


RESOURCE: Browse these URLs to learn more about MIME types, subtypes, standards, and uses:
ftp://ds.internic.net/rfc/

http://www.oac.uci.edu/indiv/ehood/MIME/1521/rfc1521../index.html

http://www.oac.uci.edu/indiv/ehood/MIME/1522/rfc1522../index.html

http://www.cis.ohio-state.edu/hypertext/faq/usenet/mail/mime-faq/top.html

http://www.netscape.com/assist/helper_apps/what-is-mime.html

http://www.netscape.com/assist/helper_apps/media-types.html

http://www.cs.indiana.edu/docproject/mail/mime.html

ftp://ftp.uu.net/networking/mail/mime/mime.ps