Module: Shrine::Plugins::DataUri::ClassMethods

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

Instance Method Summary collapse

Instance Method Details

#data_uri(uri, filename: nil) ⇒ Object

Parses the given data URI and creates an IO object from it.

io = Shrine.data_uri("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA")
io #=> #<Shrine::Plugins::DataUri::DataFile>
io.content_type #=> "image/png"
io.size         #=> 21
io.read         # decoded content

61
62
63
64
65
66
# File 'lib/shrine/plugins/data_uri.rb', line 61

def data_uri(uri, filename: nil)
  instrument_data_uri(uri) do
    info = parse_data_uri(uri)
    create_data_file(info, filename: filename)
  end
end