ns_guesstype - Lookup MIME type based on file extension
This command guesses and returns the MIME type of a file, based on the extension of filename. A large set of default extension to MIME type mappings is built into the command:
Return the MIME type for the provided filename based on its file extension.
The MIME type returned for a file extension can be overridden in the NaviServer configuration file, and new mappings can be added, e.g.
ns_section "ns/mimetypes" { ns_param ".xls" "application/vnd.ms-excel" ;# Add a mapping for Excel files ns_param ".sjis_html" "text/html; charset=shift_jis" ;# Adding a mapping, specifying charset ns_param ".adp" "text/html; charset=UTF-8" ;# Overriding an existing mapping }
The MIME type to be returned for files with unrecognized or missing extensions can also be specified in the "ns/mimetypes" section of the configuration file, e.g.
ns_section "ns/mimetypes" { ns_param default "*/*" ;# MIME type for unrecognized extension. ns_param noextension "*/*" ;# MIME type for missing extension. }
If default is not configured, "*/*" will be returned for files with unrecognized extensions. If noextension is not configured, the MIME type configured as default (or "*/*") will be used.
(Assuming configured with the examples above)
% ns_guesstype "hello.jpg" image/jpeg % ns_guesstype "hello.xls" application/vnd.ms-excel % ns_guesstype "hello.html" text/html % ns_guesstype "world.adp" text/html; charset=UTF-8 % ns_guesstype somefile */*