diff --git a/carrierwave.gemspec b/carrierwave.gemspec index fdf06bc8b..8dce30fbe 100644 --- a/carrierwave.gemspec +++ b/carrierwave.gemspec @@ -25,7 +25,7 @@ Gem::Specification.new do |s| s.add_dependency "activemodel", ">= 5.0.0" s.add_dependency "mini_mime", ">= 0.1.3" s.add_dependency "image_processing", "~> 1.1" - s.add_dependency "mimemagic", ">= 0.3.0" + s.add_dependency "marcel", "~> 1.0.0" s.add_dependency "addressable", "~> 2.6" s.add_dependency "ssrf_filter", "~> 1.0" if RUBY_ENGINE == 'jruby' diff --git a/lib/carrierwave/sanitized_file.rb b/lib/carrierwave/sanitized_file.rb index 59cebda2f..6ca023d51 100644 --- a/lib/carrierwave/sanitized_file.rb +++ b/lib/carrierwave/sanitized_file.rb @@ -1,8 +1,7 @@ require 'pathname' require 'active_support/core_ext/string/multibyte' require 'mini_mime' -require 'mimemagic' -require 'mimemagic/overlay' +require 'marcel' module CarrierWave @@ -262,7 +261,7 @@ def to_file def content_type @content_type ||= existing_content_type || - mime_magic_content_type || + marcel_magic_content_type || mini_mime_content_type end @@ -329,14 +328,14 @@ def existing_content_type end end - def mime_magic_content_type + def marcel_magic_content_type if path type = File.open(path) do |file| - MimeMagic.by_magic(file).try(:type) + Marcel::Magic.by_magic(file).try(:type) end if type.nil? - type = ::MiniMime.lookup_by_filename(path).try(:content_type) + type = Marcel::Magic.by_path(file).try(:type) type = 'invalid/invalid' unless type.nil? || type.start_with?('text/') end diff --git a/spec/sanitized_file_spec.rb b/spec/sanitized_file_spec.rb index 6b79ada5a..4f33bd748 100644 --- a/spec/sanitized_file_spec.rb +++ b/spec/sanitized_file_spec.rb @@ -378,7 +378,7 @@ expect(sanitized_file.content_type).to eq("application/octet-stream") end - it "should detect content type correctly using MagicMime when content_type is not set" do + it "should detect content type correctly using Marcel when content_type is not set" do sanitized_file.content_type = nil sanitized_file.move_to(file_path("new_dir","gurr.png"))