Skip to content

Instantly share code, notes, and snippets.

@rinaldifonseca
Forked from bendangelo/PaperclipStringFile
Created May 4, 2018 03:54
Show Gist options
  • Save rinaldifonseca/1344c7dba6b31e9f9fbbe89c3aa0999e to your computer and use it in GitHub Desktop.
Save rinaldifonseca/1344c7dba6b31e9f9fbbe89c3aa0999e 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