You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(The validation uses the 'active_storage_validations' gem but the problem is most certainly not coming from there.)
This works for intact PNG files. A deliberately broken PNG file will be accepted and saved though. My test file is 5 KB of zero bytes that I named "broken.png" and uploaded to Rails.
Expected behavior
One of…
ActiveStorage detect broken image files by trying to open them with Minimagick/Imagemagick as a validation.
ActiveStorage offers a common validation to detect broken images. (I tried to write my own custom validator to run the file through Minimagick but it I could not find a way to access the blob's data in the model before a ".save".)
Creating variants does not just throw an exception.
Actual behavior
The file gets saved by ActiveStorage with content_type='image/png'. I suspect that 'marcel' and 'mimemagick' (which I believe are used for the content type detection) can't figure out what this file is and just look at the '.png' suffix.
Once a template tries to render a variant using the Screenshot.medium_image method it will call Minimagick and fail:
convert /tmp/ActiveStorage-21670-… failed with error:
convert-im6.q16: improper image header `/tmp/ActiveStorage-21670-…' @ error/png.c/ReadPNGImage/4092.
convert-im6.q16: no images defined `/tmp/image_processing….png' @ error/convert.c/ConvertImageCommand/3258.
System configuration
Rails version: 6.0.3.4
Ruby version: 2.6.5p114
The text was updated successfully, but these errors were encountered:
For your information, this issue was solved in October 2022 by @kukicola as mentioned in the thread.
The solution is to add the processable_image validator as shown below. It will validate that the image can be processed by MiniMagick or Vips.
TL;DR There is no way to detect broken image files. So exceptions are thrown later when ActiveStorage tries to render variants.
I originally submitted this issue to rails/rails#40493 but was directed here.
Steps to reproduce
Create a controller action that receives uploaded image files. A part from my Rails application:
My model:
(The validation uses the 'active_storage_validations' gem but the problem is most certainly not coming from there.)
This works for intact PNG files. A deliberately broken PNG file will be accepted and saved though. My test file is 5 KB of zero bytes that I named "broken.png" and uploaded to Rails.
Expected behavior
One of…
Actual behavior
The file gets saved by ActiveStorage with content_type='image/png'. I suspect that 'marcel' and 'mimemagick' (which I believe are used for the content type detection) can't figure out what this file is and just look at the '.png' suffix.
Once a template tries to render a variant using the Screenshot.medium_image method it will call Minimagick and fail:
System configuration
Rails version: 6.0.3.4
Ruby version: 2.6.5p114
The text was updated successfully, but these errors were encountered: