ImageProcessing::Error if extension is missing

Hey, I’m using shrine for user uploads in a Ruby on Rails app. I’ve just found out that if someone tries to upload a JPEG file without the extension, the application raises the ImageProcessing::Error with this message:

Source format is multi-layer, but destination format is single-layer. If you care only about the first layer, add .loader(page: 0) to your pipeline. If you want to process each layer, see https://github.com/janko/image_processing/wiki/Splitting-a-PDF-into-multiple-images or use .saver(allow_splitting: true).

I’m able to fix that by manually editing the metadata["filename"] attribute in the database to include the .jpeg extension.

I think it’s related to this issue: https://github.com/janko/image_processing/issues/66

Is this a Shrine bug? Is there any workaround? For example, can I somehow use the infer_extension plugin, but only for files with a missing extension?

Thanks!

Hi, yes, it’s related to that issue. You should be able to work around the issue by adding .saver(allow_splitting: true) to the builder:

magick = ImageProcessing::MiniMagick
  .source(...)
  .saver(allow_splitting: true)

# ...

Alternatively, you should be able to use the infer_extension plugin as you said. By default it only adds the extension when it would otherwise be empty, so you should be good.

1 Like