How to save a base64 string as an image using ruby

前端 未结 4 1107
抹茶落季
抹茶落季 2020-11-29 23:26

I\'m integrating my Ruby on Rails app with a usps shipping system. Once you make a postage request, you pay for that postage and it\'s nonrefundable.

Postage reques

4条回答
  •  青春惊慌失措
    2020-11-30 00:18

    require 'RMagick'
    data = params[:image_text]# code like this  data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABPUAAAI9CAYAAABSTE0XAAAgAElEQVR4Xuy9SXPjytKm6ZwnUbNyHs7Jc7/VV9bW1WXWi9q
    image_data = Base64.decode64(data['data:image/png;base64,'.length .. -1])
    new_file=File.new("somefilename.png", 'wb')
    new_file.write(image_data)
    

    After you can use image as a file Photo.new(image: image)#save using paperclip in Photo model

提交回复
热议问题