Sha256: a1bd0449137e0baabd118da1ec54122f512b6b6939e64a6eab7357db7ce19f06
Contents?: true
Size: 738 Bytes
Versions: 14
Compression:
Stored size: 738 Bytes
Contents
module Paperclip class FileCommandContentTypeDetector SENSIBLE_DEFAULT = "application/octet-stream" def initialize(filename) @filename = filename end def detect type_from_file_command end private 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 end end
Version data entries
14 entries across 14 versions & 1 rubygems