Commit 1bcd49f4 by Jon Yurek

Refactor DataUriAdapter a little

parent 38a6b4dc
......@@ -3,9 +3,8 @@ module Paperclip
REGEXP = /^data:([-\w]+\/[-\w\+]+);base64,(.*)/
def initialize(target)
@data_uri_parts = target.match(REGEXP) || []
deserialize
def initialize(target_uri)
@target_uri = target_uri
cache_current_values
@tempfile = copy_to_tempfile
end
......@@ -14,17 +13,12 @@ module Paperclip
def cache_current_values
self.original_filename = 'base64.txt'
@content_type = @data_uri_parts[1]
@content_type ||= 'text/plain'
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
def deserialize
@target = StringIO.new(Base64.decode64(@data_uri_parts[2]))
end
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment