开发者

base64 decoding by paperclip in rails 3

开发者 https://www.devze.com 2023-03-25 01:01 出处:网络
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 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 ]

0

精彩评论

暂无评论...
验证码 换一张
取 消