Base64 decode paper clip in rails 3

I am developing a server server for my iphone application. I need to upload an image from my Iphone application to rails server.

I have a base64 encoded image in a mail request from my application that I need to parse and send to the Paperclip plugin to recalibrate the image. So can anyone suggest me how to do this.

Help me!!!. Thanks in advance.

+6
source share
2 answers

To save the image with the correct extension, you must specify the type of content. It's very nice to have this in your model as a method 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 
+10
source

Try the following:

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

[source: base64 photo and paperclip -Rails ]

+3
source

Source: https://habr.com/ru/post/894276/


All Articles