Thursday, June 24, 2010

Viewing File Attachments - setup with webserver

Viewing File Attachments

When viewing a file attachment, the browser invokes a viewer based on the content-type Multipurpose Internet Mail Extensions (MIME) category sent in the response header from the web server.

For example, if the user tried to view an MP3 file, the response header sent to the browser by the web server would indicate the audio/MPEG content type.

HTTP/1.1 200 OK
Server: Microsoft-IIS/5.0
Date: Mon, 01 Oct 2001 21:25:51
GMT ​Content-Type: audio/mpeg ​Accept-Ranges:
bytes Last-Modified: Mon, 01 Oct 2001 21:00:26
GMT ETag: "78e21918bc4ac11:cc8"
Content-Length: 60

Notice that the Content-Type is audio/mpeg. The browser uses this MIME type to determine that a viewer for audio/MPEG is appropriate. If the web server did not send this content-type header, the browser would not be able to determine the nature of the file being transmitted, and it would be unable to invoke the correct application. The browser would try to display the file as text/plain, which might be the wrong assumption.

The web server determines the MIME type by looking at the extension of the attachment file and mapping it to a MIME type. The mapping is done in the following ways, depending on the web server and platform:

*

For Microsoft IIS, the mapping is done by using the standard Microsoft Windows extension association mechanism.
*

For Apache, the mapping is done by editing a configuration file called mime.types.
*

For WebLogic, a file called web.xml does the mapping.

The file web.xml is located in the WEB-INF subdirectory. This file contains a section that looks like this:




doc


application/msword




xls


application/vnd.ms-excel



Let's say you want to add an extension that causes log files to be interpreted as plain text files.

To determine the correct MIME type, check Request for Comments (RFC) documents 2045, 2046, 2047, 2048, and 2077, which discuss internet media types and the internet media type registry.

After checking the RFCs, you determine that the correct MIME type is text/plain. The following is an example of code you would add to the previous section of web.xml:




doc


application/msword




log


​text/plain




xls


application/vnd.ms-excel



Once you save the file, the log extension is associated with the content type of text/plain.

Note. You must restart the WebLogic server before these changes are recognized.

Similar mappings can be achieved on other web servers, such as IBM WebSphere or Netscape Enterprise Server.

See your web server documentation.

Note. When trying to view the objects, the extension must exactly match what is set up in the web.xml file. This value is case-sensitive. If the object view appears garbled, chances are that either the extension is not set up in the web.xml file or there is a case mismatch.

source: http://download.oracle.com/docs/cd/E15645_01/pt850pbr0/eng/psbooks/tpcd/book.htm?File=tpcd/htm/tpcd11.htm#H3002

No comments: