module Shrine::Plugins::DataUri::FileMethods

Public Instance Methods

base64() click to toggle source

Returns contents of the file base64-encoded.

# File lib/shrine/plugins/data_uri.rb, line 144
def base64
  binary = open { |io| io.read }
  result = Base64.strict_encode64(binary)
  binary.clear # deallocate string
  result
end
data_uri() click to toggle source

Returns the data URI representation of the file.

# File lib/shrine/plugins/data_uri.rb, line 139
def data_uri
  @data_uri ||= "data:#{mime_type || "text/plain"};base64,#{base64}"
end