這是當我嘗試上傳不是圖像的東西時獲得的消息,例如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