这是当我尝试上传不是图像的东西时获得的消息,例如mp3。Ruby on rails - 无法使用MiniMagick/CarrierWave Uploader进行操作
Failed to manipulate with MiniMagick, maybe it is not an image? Original Error: MiniMagick::Invalid
所以我试图通过检查文件扩展名来提供一个条件。只有调整大小,如果它不是一个MP3。
下面是使用CarrierWave我FileUploader:
class FileUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
...
if File.extname(File.name) != ".mp3"
process :resize_to_fit => [100, 100]
version :thumb do
process :resize_to_fit => [80, 80]
end
end
...
end
File.name提供我只有名称,没有当前文件的扩展名。你知道给我提供名字+扩展名的变量吗?
编辑:
我已经找到一个替代在我的控制器:
def create
@myfile = File.new(params[:icon])
if @myfile.save
if @myfile.file.file.extension != "mp3"
@myfile.file.resize_to_fit(100, 100)
@file.save
end
end
但现在我坚持了我的CarrierWave FileUploader:
version :thumb do
process :resize_to_fit => [80, 80]
end
它变得太复杂,我只需要MiniMagick图像
我只需要一个小条件:
if file_is_image? ==>调整大小+生成缩略图
别的==>无能为力
感谢
刚一说明:为什么你有两个minimagick和rmagick包括在内? – Tigraine
我实际上只使用MiniMagick这只是一个错误,谢谢。 – user1560922