Module: Shrine::Plugins::RackFile::ClassMethods

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

Instance Method Summary collapse

Instance Method Details

#rack_file(hash) ⇒ Object

Accepts a Rack uploaded file hash and wraps it in an IO object.


11
12
13
14
15
16
17
18
19
20
21
# File 'lib/shrine/plugins/rack_file.rb', line 11

def rack_file(hash)
  if hash[:filename]
    # Rack can sometimes return the filename binary encoded, so we force
    # the encoding to utf-8
    hash = hash.merge(
      filename: hash[:filename].dup.force_encoding(Encoding::UTF_8)
    )
  end

  Shrine::RackFile.new(hash)
end