sul-dlss / exhibits

Stanford University Libraries online exhibits showcase
https://exhibits.stanford.edu
Other
19 stars 7 forks source link

Investigate alternatives to file_validators gem #2451

Open corylown opened 2 months ago

corylown commented 2 months ago

This is used to validate the the featured image is not too large:

Spotlight::FeaturedImage.validates :image, file_size: { less_than: 10.megabytes }

It's possibly unmaintained: https://github.com/musaffa/file_validators

corylown commented 2 months ago

Carrierwave still lists the file_validators gem as one of the solutions for validating file size: https://github.com/carrierwaveuploader/carrierwave/wiki/How-to%3A-Validate-image-file-size (wiki page last updated in 2020).

The first solution listed is a carrierwave only solution that doesn't require any additional gems.

CarrierWave supports this since version 1.0.0.beta (2016-09-08) by defining a size_range method inside your uploader class. The method should return a Range for minimum/maximum allowed file size in bytes. For example, to allow a size of greater than or equal to 1 byte and less than or equal to 10 MB, you'd do:

def size_range 1.byte..10.megabytes end