I am using Carrierwave to handle my file uploads and now I would like to add validation so users can't upload files of 1GB or similar.
For now I have done it like this:
class Item < ActiveRecord::Base
mount_uploader :image, ImageUploader
validate :file_size
def file_size
errors[:image] << "too big" if self.image.parametres[:size] > 100000
end
end
The problem is that I have a feeling this validation works after file is already processed. After I want to upload big file of 30MB web site is stuck a couple of minutes and then it informs me file is too big. It seems to me file is uploaded in cache and then validation runs. This is not really acceptable.
Is there any other way to run validation? Thank you!