Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

base64 decoding by paperclip in rails 3

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.

like image 305
saket Avatar asked Aug 04 '11 11:08

saket


2 Answers

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
like image 126
Tombart Avatar answered Oct 25 '22 12:10

Tombart


Try this:

sio = StringIO.new(Base64.decode64(string))

[ source: base64 photo and paperclip -Rails ]

like image 27
amaseuk Avatar answered Oct 25 '22 11:10

amaseuk