base64 照片和回形针 -Rails [英] base64 photo and paperclip -Rails

查看:28
本文介绍了base64 照片和回形针 -Rails的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用回形针处理 base64 照片.
当我尝试时:

I want to handle a base64 photo with paperclip.
When I try:

photo = Photo.new 
string = base64string

photo.photo = StringIO.new(Base64.decode64(string))
photo.save

它不起作用.为什么?

提前致谢.

推荐答案

确保你使用的StringIO是回形针打开的那个.https://github.com/thoughtbot/paperclip/blob/master/lib/paperclip/upfile.rb

Make sure that the StringIO you are using is the paperclip opened one. https://github.com/thoughtbot/paperclip/blob/master/lib/paperclip/upfile.rb

 sio = StringIO.new(Base64.decode64(string))
 puts sio.respond_to?(:original_filename)
 puts sio.respond_to?(:content_type)

它需要有这些方法才能让回形针与 StringIO 一起工作.确保它正在设置它们.

It needs to have those methods in order to have paperclip work with StringIO. Make sure it is setting them.

这篇关于base64 照片和回形针 -Rails的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆