Module: Shrine::Plugins::KitheDerivatives::InstanceMethods

Defined in:
lib/shrine/plugins/kithe_derivatives.rb

Instance Method Summary collapse

Instance Method Details

#extract_metadata(io, derivative: nil, **context) ⇒ Object

Override to fix “filename” metadata to be something reasonable, regardless of what if anything was the filename of the IO being attached. shrine S3 will insist on setting a default content-disposition with this filename.



38
39
40
41
42
43
44
45
46
47
# File 'lib/shrine/plugins/kithe_derivatives.rb', line 38

def (io, derivative:nil, **context)
  result = super

  if derivative && context[:record] && result["mime_type"]
    extension = MiniMime.lookup_by_content_type(result["mime_type"] || "")&.extension || "bin"
    result["filename"] = "#{context[:record].friendlier_id}_#{derivative}.#{extension}"
  end

  result
end