Class: RCS::MimeType

Inherits:
Object
  • Object
show all
Defined in:
lib/rcs-common/mime.rb

Class Method Summary collapse

Class Method Details

.get(file) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/rcs-common/mime.rb', line 40

def self.get(file)
  begin
    # ask for the mime type
    type = MIME::Types.type_for(file)

    # if there are multiple choices, get the first one
    type = type.first if type.is_a?(Array)
  rescue Exception => e
    type = nil
  end

  # special case for IE mobile not understanding this
  if File.extname(file) == '.cab' then
    type = MIME::Type.new('binary/octet-stream')
  end

  # default if none is found
  type = MIME::Type.new('binary/octet-stream') if type.nil?

  # convert from MIME::Type to String
  return type.to_s
end