Class: Shrine::Plugins::KitheDetermineMimeType

Inherits:
Object
  • Object
show all
Defined in:
lib/shrine/plugins/kithe_determine_mime_type.rb

Overview

Custom kithe logic for determining mime type, using the shrine mime_type plugin.

We start out using the ‘marcel` analyzer. Marcel analyzer is pure-ruby and fast. It’s from Basecamp and is what ActiveStorage uses. It is very similar to :mimemagic (and uses mimemagic under the hood), but mimemagic seems not to be maintained with up to date magic db? github.com/minad/mimemagic/pull/66

But marcel is not able to catch some of our MP3s as audio/mpeg. The ‘mediainfo` CLI is, and is one of the tools Harvard FITS uses. If marcel came up blank, AND we are configured to use mediainfo CLI (which by default we will be if it’s available), we will try shelling out to mediainfo command line.

github.com/MediaArea/MediaInfo

Ensure that if mime-type can’t be otherwise determined, it is assigned “application/octet-stream”, basically the type for generic binary.

Class Method Summary collapse

Class Method Details

.load_dependencies(uploader) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/shrine/plugins/kithe_determine_mime_type.rb', line 22

def self.load_dependencies(uploader, *)
  uploader.plugin :determine_mime_type, analyzer: -> (io, analyzers) do
    mime_type = analyzers[:marcel].call(io)


    if Kithe.use_mediainfo && mime_type == "application/octet-stream" || mime_type.blank?
      mime_type = Kithe::MediainfoAnalyzer.new.call(io)
    end

    mime_type = "application/octet-stream" if mime_type.blank?

    mime_type
  end
end