This is what I do:
In the controller: -
dataurl = params[:dataURL] io = FilelessIO.new(Base64.decode64(dataurl)) io.original_filename = "foobar.jpeg" io.content_type = "image/jpeg" p = SketchilyTest.new p.image = io p.save
Model: -
class FilelessIO < StringIO attr_accessor :original_filename attr_accessor :content_type end class SketchilyTest < ActiveRecord::Base attr_accessible :desc, :image mount_uploader :image, BaseSixtyfourEncodedUploader end
BaseSixtyfourEncodedUploader is a simple carrier gem loader.
The problem is that I am not getting any errors and the image is loading, but its damage.
When I try to open it in a browser, I get this error:
The image "http://localhost:3000/uploads/sketchily_test/image/41/foobar.jpeg" cannot be displayed because it contains errors.
Also note that I can recover an image from my base64_encoded data from my database. But it was not possible to save it as a jpeg image with a carrier.
source share