Commit 1bcd49f4 by Jon Yurek

Refactor DataUriAdapter a little

parent 38a6b4dc
...@@ -3,9 +3,8 @@ module Paperclip ...@@ -3,9 +3,8 @@ module Paperclip
REGEXP = /^data:([-\w]+\/[-\w\+]+);base64,(.*)/ REGEXP = /^data:([-\w]+\/[-\w\+]+);base64,(.*)/
def initialize(target) def initialize(target_uri)
@data_uri_parts = target.match(REGEXP) || [] @target_uri = target_uri
deserialize
cache_current_values cache_current_values
@tempfile = copy_to_tempfile @tempfile = copy_to_tempfile
end end
...@@ -14,17 +13,12 @@ module Paperclip ...@@ -14,17 +13,12 @@ module Paperclip
def cache_current_values def cache_current_values
self.original_filename = 'base64.txt' self.original_filename = 'base64.txt'
data_uri_parts ||= @target_uri.match(REGEXP) || []
@content_type = @data_uri_parts[1] @content_type = data_uri_parts[1] || 'text/plain'
@content_type ||= 'text/plain' @target = StringIO.new(Base64.decode64(data_uri_parts[2] || ''))
@size = @target.size @size = @target.size
end end
def deserialize
@target = StringIO.new(Base64.decode64(@data_uri_parts[2]))
end
end 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