本文介绍了使用带有 Carrierwave 的 base64 图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想执行与 base64 照片和回形针 -Rails 类似的事情,但使用载波.谁能解释我在 Carrierwave 中使用 base64 图像吗?
I want to perform the similar thing as from base64 photo and paperclip -Rails, but with Carrierwave. Could anybody explain me using of base64 images in Carrierwave?
推荐答案 class ImageUploader < CarrierWave::Uploader::Base class FilelessIO < StringIO attr_accessor :original_filename attr_accessor :content_type end before :cache, :convert_base64 def convert_base64(file) if file.respond_to?(:original_filename) && file.original_filename.match(/^base64:/) fname = file.original_filename.gsub(/^base64:/, '') ctype = file.content_type decoded = Base64.decode64(file.read) file.file.tempfile.close! decoded = FilelessIO.new(decoded) decoded.original_filename = fname decoded.content_type = ctype file.__send__ :file=, decoded end file end更多推荐
使用带有 Carrierwave 的 base64 图像
发布评论