Reputation: 267
This is the message that I get when I try to upload something that is not an image for example an mp3.
Failed to manipulate with MiniMagick, maybe it is not an image? Original Error: MiniMagick::Invalid
So I tried to put a condition by checking the file extension. Only resize if It's not an mp3.
Here is my FileUploader using CarrierWave:
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 provide me only the name without the extension of the current file. Do you know the variable which provide me the name + the extension ?
EDIT:
I have found an alternative in my controller:
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
But now I'm stuck with on my CarrierWave FileUploader:
version :thumb do
process :resize_to_fit => [80, 80]
end
It's getting too complicated, I need MiniMagick only for images
I just need a small condition:
if file_is_image? ==> resize + create a thumbnail
else ==> do nothing
thanks
Upvotes: 0
Views: 1418
Reputation: 115531
process :resize_to_fit => [100, 100]; :if => :processable?
def processable? upload_name
File.extname(upload_name.path) != ".mp3"
end
Upvotes: 1