Sha256: cded2b8ba81730b5a37f59d0e04a953460c5fb8c5fbb7fc55d6c59bdb7eace2d
Contents?: true
Size: 822 Bytes
Versions: 1
Compression:
Stored size: 822 Bytes
Contents
class File def self.mime_type?(file) case file when File, Tempfile unless RUBY_PLATFORM.include? 'mswin32' mime = `file --mime -br "#{file.path}"`.strip else mime = EXTENSIONS[File.extname(file.path).gsub('.','').downcase.to_sym] end when String mime = EXTENSIONS[(file[file.rindex('.')+1, file.size]).downcase.to_sym] unless file.rindex('.').nil? when StringIO temp = File.open(Dir.tmpdir + '/upload_file.' + Process.pid.to_s, "wb") temp << file.string temp.close mime = `file --mime -br "#{temp.path}"` mime = mime.gsub(/^.*: */,"") mime = mime.gsub(/;.*$/,"") mime = mime.gsub(/,.*$/,"") File.delete(temp.path) end return mime || 'unknown/unknown' end def self.extensions EXTENSIONS end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
futuresinc-mimetype-fu-0.1.0 | lib/mimetype_fu.rb |