我有一个图片文件的base64编码字符串,我需要使用Paper Clip保存它。
我的控制器代码是:
@driver = User.find(6)
encoded_file = Base64.encode64(File.open('/pjt_path/public/test.jpg').read)
decoded_file = Base64.decode64(encoded_file)
@driver.profile_pic = StringIO.open(decoded_file)
@driver.save
在我的用户模型中
has_attached_file :profile_pic, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => '/icon.jpg'
目前该文件被保存为文本文件(stringio.txt)。但是当我将扩展名更改为JPG时,我可以将其视为图像。如何使用StringIO正确命名图像。
我正在使用Rails 3.2,Ruby 1.9.2,Paperclip 3.0.3。