Note that this validation runs both after the file is uploaded and after CarrierWave has processed the image. If your base uploader includes a filter to resize the image then the validation will be run against the resized image, not the original one that was uploaded. If this causes a problem for you, then you should avoid using a resizing filter on the base uploader and put any specific size requirements in a version instead.
So instead of this:
require 'carrierwave/processing/mini_magick'
class LogoUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
process :quality => 80
process :resize_to_limit => [800, 800]
process :convert => 'png'
# ...
end
Do this:
require 'carrierwave/processing/mini_magick'
class LogoUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
process :convert => 'png'
version :medium do
process :quality => 80
process :resize_to_limit => [800, 800]
end
# ...
end
I discovered this was caused by some coincidence: I was migrating from paperclip and some records already had uploads, so carrierwave was thinking they are valid. I'm hosting on Azure, so I used
carrierwave-azure
which makes an HTTP request to get the file size and returns nil, instead of 0, if the file is unavailable. The solution was to just clear the outdated values in the upload column. Maybe this helps someone in a similar situation.Anyway, this validator is almost useless(besides making a human readable file size in the error message), as you can just use the standard Rails length validator.