請幫我...我用回形針上傳畫布標記(base64)中的1張圖片到aws-s3。回形針與base64:undefined方法`stringify_keys'爲#<字符串:0xb46dba14>
我的控制器
def create
decoded_file = Base64.decode64(params[:photo])
begin
file = Tempfile.new(['test', '.jpg'])
file.binmode
file.write decoded_file
file.close
@photo.photo = file
if @photo.save
render :json => {:message => "Successfully uploaded the profile picture."}
else
render :json => {:message => "Failed to upload image"}
end
ensure
file.unlink
end
end
型號
class Photo < ActiveRecord::Base
has_attached_file :photo, styles: { thumbnail: "150x200#"}, default_style: :thumbnail
end
和錯誤:
NoMethodError at /photos
===================================
> undefined method `stringify_keys' for #<String:0xb46dba14>
activerecord (4.0.0) lib/active_record/attribute_assignment.rb, line 17
現在,工作很好。但我刪除行「file.close」。非常感謝你。 – JohnEvans
我很抱歉,因爲我沒有投票給你。因爲投票需要15個代表。 :D – JohnEvans
hehe我剛剛提出了你的問題,現在你只需要再次投票! :) –