Reputation: 1392
I am trying to create thumb for pictures or videos in the same uploader for an ad model...
So far, I am trying to create a conditional thumb like that:
version :thumb do
process :resize_to_limit => [50, 50] if %w(jpg jpeg gif png).include?(file.extension)
process :screenshot => 5 if %w(mpg avi).include?(file.extension)
end
end
but apparently, I get errors on the file.extension part like this
NameError: undefined local variable or method `file'
Does anyone know how to get the file extension in uploader?
Upvotes: 0
Views: 905
Reputation: 4264
Your code looks like the carrierwave generated uploader class and if I understand your question correctly, you are looking for a way to restrict the type of file that can be turned into a thumbnail. You can whitelist the types of files the uploader class will accept - so in the uploader class where your :thumb method is located include the following :
# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:
def extension_white_list
%w(jpg jpeg gif png)
end
Upvotes: 3