Upload an image from JSON with rails
- by Dougui
I have an application created with PhoneGap and Backbone. I upload a file as JSon and my server receive data like this :
data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/...
I'm trying to write the file like this :
File.open("#{Rails.root}/public/images/#{self.id}.jpg", "w+") do |f|
f.write(data)
end
It's not working and I don't know what to do. When I'm trying to open the file I have this message "Not a JPEG file: starts with 0x64 0x61".
Do you have a solution?