Serving Application-Specific Documents


How can I return an application-specific document file as binary data?
Rename the file to have the extension ".bin", in which case it should be transferred as a stream of 8-bit bytes. Our local UNIX-based HTTP servers do this by default.

The server-wide list of mappings is in /usr/local/httpd/conf/mime.types, a portion of which is below.

application/mac-binhex40 hqx
application/msword word
application/octet-stream bin
application/pdf pdf
application/rtf rtf
application/x-latex latex
application/zip zip
audio/basic au snd
audio/x-aiff aif aiff aifc
audio/x-wav wav
image/gif gif
image/jpeg jpeg jpg jpe
text/html html htm
text/plain txt
video/mpeg mpeg mpg mpe
video/quicktime qt mov

If you want to serve file types that are not supported by the default mime.types file, you can augment that file with your own definitions. To do this, create a file called .htaccess in the directory where the files you want to serve are located. In the .htaccess file, type:

AddType   mime-type   .ext
where mime-type is the MIME type and .ext is the file name extension you intend to use for files to be associated with mime-type. You must include a period (.) before the extension. You can list several exts separated by blanks. For example, see the image/jpeg entry above.

If you are not sure what mime-type and .ext to use, do not create a .htaccess file. Instead, send mail to your Webmaster or to www@www.utexas.edu to ask for help.

Save the .htaccess file and store all ext files in the same directory. Then, all files in the directory that end in .ext will be mapped into mime-type and handled properly by the server.

For example, if you wanted to store and serve Lotus 1-2-3 files with the extensions wks, wk1, wk2, wk3, and wk4, you should type:

AddType application/lotus123 .wks .wk1 .wk2 .wk3 .wk4
Note: Using .htaccess files in this way requires the server to search for and parse a data file upon EVERY HTTP retrieval. This can result in slower delivery of your data, so we recommend only using it when necessary.
- TeamWeb Answers

  Reviewed 2002 October 30
  Comments to www@www.utexas.edu