module Shrine::Plugins::DataUri::ClassMethods

  1. lib/shrine/plugins/data_uri.rb

Methods

Public Instance

  1. data_uri

Public Instance methods

data_uri (uri)

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

Shrine.data_uri("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA")
#=> #<Shrine::Plugins::DataUri::DataFile>
[show source]
# File lib/shrine/plugins/data_uri.rb, line 91
def data_uri(uri)
  info = parse_data_uri(uri)

  content_type = info[:content_type] || DEFAULT_CONTENT_TYPE
  content      = info[:base64] ? Base64.decode64(info[:data]) : CGI.unescape(info[:data])
  filename     = opts[:data_uri_filename]
  filename     = filename.call(content_type) if filename

  data_file = DataFile.new(content, content_type: content_type, filename: filename)
  info[:data].clear

  data_file
end