Please help me... I use paperclip to upload 1 picture in the canvas tag (base64) to aws-s3.
My Controller
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
Model
class Photo < ActiveRecord::Base
has_attached_file :photo, styles: { thumbnail: "150x200#"}, default_style: :thumbnail
end
And errors :
NoMethodError at /photos
===================================
> undefined method `stringify_keys' for #<String:0xb46dba14>
activerecord (4.0.0) lib/active_record/attribute_assignment.rb, line 17
Okay, I think I got something.
There are 2 potential problems:
@post.save function might be incorrectI don't know about the canvas stuff.... so I'm going to give you my best shot with the @post.save:
def create
decoded_file = Base64.decode64(params[:photo])
begin
file = Tempfile.new(['test', '.jpg'])
file.binmode
file.write decoded_file
file.close
params[:photo] = file
@photo.new(photo_params)
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
private
def photo_params
params.permit(:photo)
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With