ファイルが添付されたPictureというモデルがあります。私が使用しているソフトウェア:
*Rails 3
*Ruby 1.9.3
*Paperclip
*ImageMagick
私のモデルは:
class Picture < ActiveRecord::Base
attr_accessible :picturefile,:picturefile_file_name,:picturefile_content_type,:picturefile_file_size,:picturefile_updated_at
has_attached_file :picturefile,
:styles => {
:thumb=> "100x100#"},
:storage => :s3,
:s3_credentials => Rails.root.join('config','s3.yml'),
:path => "/travels/:style/:id/:basename.:extension"
end
そして私のコントローラーにはこれがあります:
StringIO.open(Base64.decode64(params[:Route][:CoverPicture][:File][:EncodedContent])) do |data|
fotocov_t=Picture.create({
:picturefile=>data
})
travel.pictures = [fotocov_t] #this assigns the new picture to a travel i created before the picture
end
ご覧のとおり、文字列をアップロードしていますが、アップロードしたいのは、でエンコードされた文字列によって作成された画像です。
params[:Route][:CoverPicture][:File][:EncodedContent]
複数のアプローチを試しましたが、テキストファイルを保存し続けています。
テキストファイルをアップロードする代わりに、ファイルを画像としてアップロードする方法を知っている人はいますか?
ありがとうございました :)