Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jan 26th, 2013  |  syntax: None  |  size: 0.38 KB  |  views: 21  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/...
  2.        
  3. File.open("#{Rails.root}/public/images/#{self.id}.jpg", "w+") do |f|
  4.   f.write(data)
  5. end
  6.        
  7. File.open("#{Rails.root}/public/images/#{self.id}.jpg", "w+") do |f|
  8.   decoded_data = Base64.decode64(data)
  9.   image_data = StringIO.new(decoded_data)
  10.   f.write(image_data)
  11. end
  12.        
  13. f.write Base64.decode64(data).force_encoding('UTF-8')