Sha256: 2ddd521707284a58601c5a580e012ee2d2805039bb65a0e7a2802bac0928ab14

Contents?: true

Size: 704 Bytes

Versions: 2

Compression:

Stored size: 704 Bytes

Contents

module Paperclip
  class DataUriAdapter < StringioAdapter

    REGEXP = /\Adata:([-\w]+\/[-\w\+]+);base64,(.*)/m

    def initialize(target_uri)
      @target_uri = target_uri
      cache_current_values
      @tempfile = copy_to_tempfile
    end

    private

    def cache_current_values
      self.original_filename = 'base64.txt'
      data_uri_parts ||= @target_uri.match(REGEXP) || []
      @content_type = data_uri_parts[1] || 'text/plain'
      @target = StringIO.new(Base64.decode64(data_uri_parts[2] || ''))
      @size = @target.size
    end

  end
end

Paperclip.io_adapters.register Paperclip::DataUriAdapter do |target|
  String === target && target =~ Paperclip::DataUriAdapter::REGEXP
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
paperclip-3.5.4 lib/paperclip/io_adapters/data_uri_adapter.rb
paperclip-3.5.3 lib/paperclip/io_adapters/data_uri_adapter.rb