encode and decode image in Base64 in rails

require "base64"

encoded_string = Base64.encode64(open("https://s3.amazonaws.com/cdn.
yourwellnessroom.com/i/pillarimages/eat/E22.jpg") { |io| io.read })

decode_img= Base64.decode64(encoded_string)

  File.open('image.png', 'wb') { |f| f.write(decode_img) }

  user.image = image.png'

  user.save


Comments

Popular Posts

How to pass hash in Postman

nginx: unrecognized service

Bootstrap Select Picker append add new item if search not exist

Reading Excel Sheets using "Roo" gem in ruby on rails

Add CORS to Nginx on AWS Elastic Beanstalk

Enable gzip compression on Elastic Beanstalk with nginx

Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'

Get video duration by URL in Ruby on Rails

site-enables nginx setting in ruby in rails