Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

string_to_file

  • Loading branch information...
commit 4a58196a2aaf79fe58ceaff1e174c952cdfc36d4 1 parent d54363d
@jywarren authored
Showing with 21 additions and 0 deletions.
  1. +21 −0 thermographer-website/config/initializers/paperclip_string.rb
View
21 thermographer-website/config/initializers/paperclip_string.rb
@@ -0,0 +1,21 @@
+# Indicate location of "identify" command:
+#Paperclip.options[:command_path] = "/usr/bin/identify"
+#Paperclip.options[:command_path] = "/usr/local/bin"
+
+# Thank you to http://bendangelo.me/?p=60
+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
+
Please sign in to comment.
Something went wrong with that request. Please try again.