class Paperclip::FileCommandContentTypeDetector
Constants
- SENSIBLE_DEFAULT
Public Class Methods
new(filename)
click to toggle source
# File lib/paperclip/file_command_content_type_detector.rb, line 5 def initialize(filename) @filename = filename end
Public Instance Methods
detect()
click to toggle source
# File lib/paperclip/file_command_content_type_detector.rb, line 9 def detect type_from_file_command end
Private Instance Methods
type_from_file_command()
click to toggle source
# File lib/paperclip/file_command_content_type_detector.rb, line 15 def type_from_file_command # On BSDs, `file` doesn't give a result code of 1 if the file doesn't exist. type = begin Paperclip.run("file", "-b --mime :file", file: @filename) rescue Terrapin::CommandLineError => e Paperclip.log("Error while determining content type: #{e}") SENSIBLE_DEFAULT end type = SENSIBLE_DEFAULT if type.nil? || type.match(/\(.*?\)/) type.split(/[:;\s]+/)[0] end