使用带有 Carrierwave 的 base64 图像

编程入门 行业动态 更新时间:2024-10-27 22:30:27
本文介绍了使用带有 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 图像

本文发布于:2023-10-11 23:57:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1483206.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   Carrierwave

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!