Class: ActionDispatch::Http::UploadedFile

Inherits:
Object
  • Object
show all
Defined in:
lib/rails/social_stream.rb

Overview

Monkey patches to Ruby on Rails

Use unix file util to prove the content type sent by the browser

Instance Method Summary collapse

Instance Method Details

#initialize_with_magic(*args, &block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rails/social_stream.rb', line 5

def initialize_with_magic(*args, &block)
  initialize_without_magic(*args, &block)

  if (unix_file = `which file`.try(:chomp)).present? && File.exists?(unix_file)
    `#{ unix_file } -v 2>&1` =~ /^file-(.*)$/
    version = $1

    @content_type =
      if version >= "4.24"
        `#{ unix_file } -b --mime-type #{ @tempfile.path }`.chomp
      else
        `#{ unix_file } -bi #{ @tempfile.path }`.chomp =~ /(\w*\/[\w+-\.]*)/
        $1
      end
  end
end