module MIME::ContentTypes

Handles MIME content type detection using file name extension.

See Also

Constants

CONTENT_TYPES

Content types are in the form of media-type/sub-type. Each content type has one or more file extentions associated with it.

The content types below are listed in alphabetical order and the extention arrays are in order of preference.

The following content types were stolen from the NGiNX webserver. NGiNX is great server, check it out at nginx.net.

Public Instance Methods

file_type(file) click to toggle source

Return the MIME content type of the file path or object.

# File lib/mime/content_types.rb, line 87
def file_type file
  filename = file.respond_to?(:path) ? file.path : file
  extension = File.extname(filename)[1..-1] # remove leading period
  type, _ = CONTENT_TYPES.find do |content_type, extentions|
    extentions.include? extension
  end
  type
end