Sha256: 5d971d4eb11d868468d16e00eeef6783a9a663bfb41b3ac04cedb058040250c9
Contents?: true
Size: 756 Bytes
Versions: 4
Compression:
Stored size: 756 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 if type.nil? || type.match(/\(.*?\)/) type = SENSIBLE_DEFAULT end type.split(/[:;\s]+/)[0] end end end
Version data entries
4 entries across 4 versions & 2 rubygems