我一直在尝试使用回形针将文件(RMagick处理的输出)上传到s3。我一直收到错误
找不到处理程序 http://upload.wikimedia.org/wikipedia/commons/thumb/4/48/EBay_logo.png/800px-EBay_logo.png=> 800像素-EBay_logo.png PNG 800x349 800x349 + 0 + 0 DirectClass 8-bit 37kb
基本上,在我的系统中 - 用户使用外部网址上传徽标,我处理徽标并修剪空白并上传到我的s3系统。我一直在使用临时文件作为中间人,但我想直接这样做:
在我的模型中,我这样做:
def fetch_and_trim_logo
puts "logo is #{logo}"
if logo_changed?
response = RestClient.get logo
if response.code == 200
img = Magick::Image::read(logo)[0]
puts "This image is #{img.columns}x#{img.rows} pixels"
trimmed_img = img.trim
puts "Trimmed image is #{trimmed_img.columns}x#{trimmed_img.rows} pixels"
temp_file = Tempfile.new(["trimmed_image",".png"])
trimmed_img.write("png:" + temp_file.path)
my_asset = visitor.user.my_assets.new
my_asset.uploaded_file = temp_file
my_asset.save
end
end
end
My My_asset Model具有所有回形针设置,如下所示:
Class MyAsset<ActiveRecord::Base
---
---
has_attached_file :uploaded_file
attr_accessible :uploaded_file
validates_attachment_size :uploaded_file, :less_than=>5.megabyte
has_attached_file :picture,
:styles => { :thumb => "300x300#" },
:default_url => "//#{ENV['CLOUDFRONT_URL']}/assets/picture_missing.png"
end
此方法有效!但是当我改变时
my_asset = visitor.user.my_assets.new
my_asset.uploaded_file = temp_file
my_asset.save
到
my_asset = visitor.user.my_assets.new
my_asset.uploaded_file = trimmed_img
my_asset.save
其中trimmed_img是RMagick处理的输出,我收到错误“No Handler found”
任何想法如何解决这个问题?
答案 0 :(得分:5)
好的,解决方法是将Magic图像对象更改为File对象,然后再将其上传到Paperlip
所以,
01-May-2015
然后使用回形针直接上传已处理的图像