Skip to content

Instantly share code, notes, and snippets.

@bendangelo
Created May 23, 2012 15:47
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bendangelo/2776043 to your computer and use it in GitHub Desktop.
Save bendangelo/2776043 to your computer and use it in GitHub Desktop.
Paperclip string to file
module Paperclip
#converts a string into a file for paperclip to save
# useage
# self.avatar = Paperclip::string_to_file('bob.png', 'image/png', 'BASE64 here')
def self.string_to_file(name, type, data)
image = StringIO.new(data)
image.class.class_eval { attr_accessor :original_filename, :content_type }
image.original_filename = name
image.content_type = type
return image
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment