Upload an image from JSON with rails
Posted
by
Dougui
on Stack Overflow
See other posts from Stack Overflow
or by Dougui
Published on 2012-10-16T00:45:13Z
Indexed on
2012/10/16
5:03 UTC
Read the original article
Hit count: 157
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?
© Stack Overflow or respective owner