Rails Image String to Image File
I currently save 开发者_如何学Pythonimage strings (this is how they are provided through API) as a binary in my database but I need to (after creation), change this to a file structure, probably using Paperclip/Carrierwave and S3.
What is the best way to convert binary to image file e.g. jpg?
This did the trick:
sio = StringIO.new(Base64.decode64(string))
[ source: base64 photo and paperclip -Rails ]
file_arr = Model.find(:all)
file_arr.each do |file|
File.open(file.name,'w'){|f| f.write(file.blob)}
end
would be my guess of how to do it. Where Model is your model .name is the name stored in the Database and .blob is the blob field...You may be able to do this via the Rails console.
This may not be the best answer but it may give you a start.
精彩评论