I am developing a server backend for my i开发者_JAVA技巧phone 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 ]
精彩评论