I am developing a server backend for my iphone application. I need to upload a picture from my Iphone app to the rails server
I have a base64 encoded image in the post request from my app which I need to parse and send to the Paperclip plugin for the re-sizing of the image.So can anybody suggest me how to do it.
Help me!!!. Thanks in advance.
In order to save image with correct extension you have to specify content type.
It's quite nice to have this in your model as method which is called before_validation
StringIO.open(Base64.decode64(self.photo_base64)) do |data|
data.original_filename = "image_name.jpg"
data.content_type = "image/jpeg"
self.photo = data
end
Try this:
sio = StringIO.new(Base64.decode64(string))
[ source: base64 photo and paperclip -Rails ]
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