Handles MIME content type detection using file name extension.
See Also¶ ↑
w3schools.com/media/media_mimeref.asp for more content types
rubygem MIME::Types for extensive content type lookup
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.
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