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.
MIME type lookup uses the built-in NaviServer MIME type table together with optional mappings from the ns/mimetypes configuration section. The lookup is based on filename extensions and is used by ns_guesstype and by file delivery code when determining the content type of served files.
The built-in MIME type table is extensive, but local overrides can still be useful. In practice, the same filename extension may be used for different content types in different deployments, or an application may need to add a site-specific extension.
ns_section ns/mimetypes {
# Add or override extension-specific mappings.
ns_param .xls application/vnd.ms-excel
ns_param .sjis_html "text/html; charset=shift_jis"
ns_param .adp "text/html; charset=UTF-8"
}
Fallback MIME types for files with unknown or missing extensions can be configured with the default and noextension parameters.
ns_section ns/mimetypes {
ns_param default */*
ns_param noextension */*
}
If default is not configured, */* is returned for files with unrecognized extensions. If noextension is not configured, the value of default is used for files without an extension.
(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 */*