Cambia Research - Supporting the Microsoft .NET Developer Community Supporting the Microsoft .NET Developer Community  

     | Home  | Articles  | Categories  | Coders  | Search  | Submit  | Contact Us    
Programming can be fun, so can cryptography; however they should not be combined. --Kreitzberg and Shneiderman

Share Your Knowledge! -- Create and submit your articles the easy way with WebWriter.

Updated:11:53 PM CT Feb 15, 2007
Posted:11:46 PM CT Feb 15, 2007

What is MIME and Why Should a Web Developer Care?

The Role of MIME in HTTP Communications

Author: Steve Lautenschlager

ReferencePolicy and StandardsASP.NETEmailMultimediaServer SideWeb
    Prev     1    2     Next  

 Summary

What does MIME stand for, how does it relate to HTTP messages and why should I, as a web developer, care?

 What is MIME?

MIME is an acronym meaning Multipurpose Internet Mail Extensions.

Originally developed in 1992, MIME was a standard created to allow the exchange of non-ASCII content over email.

Email was, and is really, an ASCII medium. MIME provides a mechanism for attaching data of non-ASCII types like images, sound files, multi-part messages, video, etc.

The key feature of a MIME encoded message is that it indicates the content-type of the encoded data.

I use the word encoded, because email was a pure ASCII medium and in order to transfer non-ASCII content, the binary data was encoded as a series of ASCII characters which could then be decoded on the other side.

As long as the email program receiving the data knows what kind of file it is, it can try to do something appropriate with the data.

All MIME headers indicate the content-type of the contained data.

 HTTP and MIME

HTTP uses MIME-like messages to transfer content. I say MIME-like because HTTP does not purport to be MIME-compliant even though it may borrow MIME concepts and HTTP messages may be in full compliance with the MIME protocol.

MIME-like headers serve to indicate the type of data contained in the message, thus allowing the receiver to decode and interpret the data and ultimately act on the data by displaying it or prompting the user for some action.


The official W3 specs for HTTP says this about the relationship between MIME and HTTP:

"The HTTP protocol is a request/response protocol. A client sends a
request to the server in the form of a request method, URI, and
protocol version, followed by a MIME-like message containing request
modifiers, client information, and possible body content over a
connection with a server. The server responds with a status line,
including the message's protocol version and a success or error code,
followed by a MIME-like message containing server information, entity
metainformation, and possible entity-body content."

 The Role of MIME-types in HTTP Responses

So, as a web developer, if you are generating an HTTP response that will be returned to a browser or other HTTP client, you will want a way to tell the browser what type of data is contained in the message you are sending. The standard MIME-type name (ie "text/plain", "image/jpeg", "application/pdf" ... ) is sent in the HTTP header to do just this.

The following C# code sample uses MIME types to indicate the the file type being returned in the HTTP response:

Deliver File from HTTP Server and Specify Its Mime-type

public void DeliverJpegFile(byte[] bytes, string fileName)

	Response.AppendHeader("Content-disposition", "attachment; filename=" + fileName);
	Response.ContentType = image/jpeg"; // this is where we indicate the MIME-type
	Response.OutputStream.Write(bytes, 0, bytes.Length);
	Response.End();

}
    Prev     1    2     Next  

Add New Comment
CR Comments by Cambia Research
advertisement
 
Steve Lautenschlager (steve)
Steve is the founder and creator of Cambia Research. Developing and maintaining the site combines his passions for technology, writing and education.
Steve holds a Ph.D. in particle physics from Duke University, has worked at CERN, the European center for particle physics (where the web was born) and in Microsoft's web division with microsoft.com, msnbc.com and other web properties. Steve is a web consultant specializing in Microsoft.NET technologies. Read more here.


 
Copyright © Cambia Research 2002-2007. All Rights Reserved. steve [ at ] cambiaresearch.com