active_storage_validations
active_storage_validations copied to clipboard
"foobar is not a valid image" for valid image (error only in production)
I have the following validation in my model:
validates :input_image,
attached: true,
content_type: ["image/png", "image/jpeg"],
dimension: {
width: { min: 10, max: 5000 },
height: { min: 10, max: 5000 }
},
size: { less_than: 25.megabytes }
When trying to attach an image that fits these criteria, it works fine on localhost (disk storage). But when trying the same image in production (using S3), I get the error Input message is not a valid image
. Unfortunately it does not specify what's not valid about it.
Any suggestions on how to debug this?
I'm using rails (7.0.4)
, and active_storage_validations (0.9.8)
.
Hm, my semi-educated guess is: you're either a) using an asynchronous job runner in production but not locally which delays image analyzation and therefore the adding of the width and height metadata the dimension validator needs or b) missing a Vips/ImageMagick processor for the uploaded files in question.
I'd try to reproduce the error using an own "development" S3 bucket locally.
a) using an asynchronous job runner in production but not locally which delays image analyzation and therefore the adding of the width and height metadata the dimension validator needs
That was it!
I have removed the dimensions validation (and kept the rest), and now it works as expected. Thank you!
I guess I can use something like fastimage
in a before_validation
callback to set the height and width. Perhaps also worth adding as an option to this gem, as I believe analyzing an attachment asynchronously is the default in Rails?
There's a mechanism for this already somewhere in ActiveStorage, I remember seeing some logic like "was the picture analyzed yet? if not, do it right away." in the AS code a few months ago. I will dive back into that.
There's a mechanism for this already somewhere in ActiveStorage, I remember seeing some logic like "was the picture analyzed yet? if not, do it right away." in the AS code a few months ago. I will dive back into that.
I think this gem by already do this. The problem might be my own code disabling analyzers altogether.
(So please don't spend time looking into this just for me.)