ruby-on-railsrails-activestoragepopplerruby-on-rails-7bootsnap

Rails 7 ActiveStorage file preview. rails app is crashing


I am trying to preview a pdf file in a rails 7 project like this:

I am using poppler & rails default active storage. I am able to store the file, link it for download but not really preiview it in a web page.

<%= image_tag @user.pdf_doc.preview(resize_to_fit: [100, 100]) %> When running the app in a docker container:

Once I hit the view, an empty image thumbnail is being shown without having the file really shown upon refreshing the page, the rails app crashes with the following error log:

rails7-on-docker-web-1    | #<Thread:0x0000ffff7acc2318 /usr/local/bundle/gems/actionpack-7.0.2.2/lib/action_controller/metal/live.rb:340 run> terminated with exception (report_on_exception is true):
rails7-on-docker-web-1    | /usr/local/bundle/gems/ffi-1.15.5/lib/ffi/library.rb:145:in `block in ffi_lib': Could not open library 'vips.so.42': vips.so.42: cannot open shared object file: No such file or directory. (LoadError)
rails7-on-docker-web-1    | Could not open library 'libvips.so.42': libvips.so.42: cannot open shared object file: No such file or directory
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/ffi-1.15.5/lib/ffi/library.rb:99:in `map'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/ffi-1.15.5/lib/ffi/library.rb:99:in `ffi_lib'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/ruby-vips-2.1.4/lib/vips.rb:573:in `<module:Vips>'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/ruby-vips-2.1.4/lib/vips.rb:570:in `<main>'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/zeitwerk-2.5.4/lib/zeitwerk/kernel.rb:35:in `require'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/image_processing-1.12.1/lib/image_processing/vips.rb:1:in `<main>'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/zeitwerk-2.5.4/lib/zeitwerk/kernel.rb:35:in `require'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activestorage-7.0.2.2/lib/active_storage/transformers/image_processing_transformer.rb:26:in `const_get'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activestorage-7.0.2.2/lib/active_storage/transformers/image_processing_transformer.rb:26:in `processor'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activestorage-7.0.2.2/lib/active_storage/transformers/image_processing_transformer.rb:17:in `process'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activestorage-7.0.2.2/lib/active_storage/transformers/transformer.rb:22:in `transform'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activestorage-7.0.2.2/app/models/active_storage/variation.rb:56:in `block in transform'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activesupport-7.0.2.2/lib/active_support/notifications.rb:206:in `block in instrument'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activesupport-7.0.2.2/lib/active_support/notifications/instrumenter.rb:24:in `instrument'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activesupport-7.0.2.2/lib/active_support/notifications.rb:206:in `instrument'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activestorage-7.0.2.2/app/models/active_storage/variation.rb:55:in `transform'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activestorage-7.0.2.2/app/models/active_storage/variant_with_record.rb:35:in `block in transform_blob'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activestorage-7.0.2.2/lib/active_storage/downloader.rb:15:in `block in open'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activestorage-7.0.2.2/lib/active_storage/downloader.rb:24:in `open_tempfile'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activestorage-7.0.2.2/lib/active_storage/downloader.rb:12:in `open'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activestorage-7.0.2.2/lib/active_storage/service.rb:90:in `open'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activestorage-7.0.2.2/app/models/active_storage/blob.rb:301:in `open'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activestorage-7.0.2.2/app/models/active_storage/variant_with_record.rb:34:in `transform_blob'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activestorage-7.0.2.2/app/models/active_storage/variant_with_record.rb:19:in `process'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activestorage-7.0.2.2/app/models/active_storage/variant_with_record.rb:14:in `processed'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activestorage-7.0.2.2/app/models/active_storage/preview.rb:105:in `variant'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activestorage-7.0.2.2/app/models/active_storage/preview.rb:63:in `url'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activestorage-7.0.2.2/app/controllers/active_storage/representations/redirect_controller.rb:12:in `show'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/actionpack-7.0.2.2/lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/actionpack-7.0.2.2/lib/abstract_controller/base.rb:214:in `process_action'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/actionpack-7.0.2.2/lib/action_controller/metal/rendering.rb:53:in `process_action'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/actionpack-7.0.2.2/lib/abstract_controller/callbacks.rb:234:in `block in process_action'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activesupport-7.0.2.2/lib/active_support/callbacks.rb:118:in `block in run_callbacks'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/actiontext-7.0.2.2/lib/action_text/rendering.rb:20:in `with_renderer'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/actiontext-7.0.2.2/lib/action_text/engine.rb:69:in `block (4 levels) in <class:Engine>'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activesupport-7.0.2.2/lib/active_support/callbacks.rb:127:in `instance_exec'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activesupport-7.0.2.2/lib/active_support/callbacks.rb:127:in `block in run_callbacks'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activesupport-7.0.2.2/lib/active_support/callbacks.rb:138:in `run_callbacks'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/actionpack-7.0.2.2/lib/abstract_controller/callbacks.rb:233:in `process_action'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/actionpack-7.0.2.2/lib/action_controller/metal/rescue.rb:22:in `process_action'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/actionpack-7.0.2.2/lib/action_controller/metal/instrumentation.rb:67:in `block in process_action'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activesupport-7.0.2.2/lib/active_support/notifications.rb:206:in `block in instrument'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activesupport-7.0.2.2/lib/active_support/notifications/instrumenter.rb:24:in `instrument'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activesupport-7.0.2.2/lib/active_support/notifications.rb:206:in `instrument'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/actionpack-7.0.2.2/lib/action_controller/metal/instrumentation.rb:66:in `process_action'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/actionpack-7.0.2.2/lib/action_controller/metal/params_wrapper.rb:259:in `process_action'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activerecord-7.0.2.2/lib/active_record/railties/controller_runtime.rb:27:in `process_action'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/actionpack-7.0.2.2/lib/abstract_controller/base.rb:151:in `process'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/actionview-7.0.2.2/lib/action_view/rendering.rb:39:in `process'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/actionpack-7.0.2.2/lib/action_controller/metal/live.rb:266:in `block (2 levels) in process'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activesupport-7.0.2.2/lib/active_support/concurrency/share_lock.rb:162:in `sharing'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activesupport-7.0.2.2/lib/active_support/dependencies/interlock.rb:37:in `running'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/actionpack-7.0.2.2/lib/action_controller/metal/live.rb:258:in `block in process'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/actionpack-7.0.2.2/lib/action_controller/metal/live.rb:343:in `block in new_controller_thread'
rails7-on-docker-web-1    | Exiting
rails7-on-docker-web-1    | [ActiveJob] [ActiveStorage::AnalyzeJob] [d5d68a12-6340-443f-a225-b3b3648bbd13]   TRANSACTION (0.8ms)  COMMIT
rails7-on-docker-web-1    | [ActiveJob] [ActiveStorage::AnalyzeJob] [d5d68a12-6340-443f-a225-b3b3648bbd13] Performed ActiveStorage::AnalyzeJob (Job ID: d5d68a12-6340-443f-a225-b3b3648bbd13) from Async(default) in 160.81ms
rails7-on-docker-web-1    | /usr/local/bundle/gems/ffi-1.15.5/lib/ffi/library.rb:145:in `block in ffi_lib': Could not open library 'vips.so.42': vips.so.42: cannot open shared object file: No such file or directory. (LoadError)
rails7-on-docker-web-1    | Could not open library 'libvips.so.42': libvips.so.42: cannot open shared object file: No such file or directory
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/ffi-1.15.5/lib/ffi/library.rb:99:in `map'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/ffi-1.15.5/lib/ffi/library.rb:99:in `ffi_lib'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/ruby-vips-2.1.4/lib/vips.rb:573:in `<module:Vips>'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/ruby-vips-2.1.4/lib/vips.rb:570:in `<main>'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/zeitwerk-2.5.4/lib/zeitwerk/kernel.rb:35:in `require'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/image_processing-1.12.1/lib/image_processing/vips.rb:1:in `<main>'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/zeitwerk-2.5.4/lib/zeitwerk/kernel.rb:35:in `require'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activestorage-7.0.2.2/lib/active_storage/transformers/image_processing_transformer.rb:26:in `const_get'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activestorage-7.0.2.2/lib/active_storage/transformers/image_processing_transformer.rb:26:in `processor'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activestorage-7.0.2.2/lib/active_storage/transformers/image_processing_transformer.rb:17:in `process'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activestorage-7.0.2.2/lib/active_storage/transformers/transformer.rb:22:in `transform'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activestorage-7.0.2.2/app/models/active_storage/variation.rb:56:in `block in transform'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activesupport-7.0.2.2/lib/active_support/notifications.rb:206:in `block in instrument'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activesupport-7.0.2.2/lib/active_support/notifications/instrumenter.rb:24:in `instrument'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activesupport-7.0.2.2/lib/active_support/notifications.rb:206:in `instrument'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activestorage-7.0.2.2/app/models/active_storage/variation.rb:55:in `transform'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activestorage-7.0.2.2/app/models/active_storage/variant_with_record.rb:35:in `block in transform_blob'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activestorage-7.0.2.2/lib/active_storage/downloader.rb:15:in `block in open'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activestorage-7.0.2.2/lib/active_storage/downloader.rb:24:in `open_tempfile'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activestorage-7.0.2.2/lib/active_storage/downloader.rb:12:in `open'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activestorage-7.0.2.2/lib/active_storage/service.rb:90:in `open'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activestorage-7.0.2.2/app/models/active_storage/blob.rb:301:in `open'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activestorage-7.0.2.2/app/models/active_storage/variant_with_record.rb:34:in `transform_blob'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activestorage-7.0.2.2/app/models/active_storage/variant_with_record.rb:19:in `process'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activestorage-7.0.2.2/app/models/active_storage/variant_with_record.rb:14:in `processed'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activestorage-7.0.2.2/app/models/active_storage/preview.rb:105:in `variant'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activestorage-7.0.2.2/app/models/active_storage/preview.rb:63:in `url'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activestorage-7.0.2.2/app/controllers/active_storage/representations/redirect_controller.rb:12:in `show'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/actionpack-7.0.2.2/lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/actionpack-7.0.2.2/lib/abstract_controller/base.rb:214:in `process_action'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/actionpack-7.0.2.2/lib/action_controller/metal/rendering.rb:53:in `process_action'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/actionpack-7.0.2.2/lib/abstract_controller/callbacks.rb:234:in `block in process_action'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activesupport-7.0.2.2/lib/active_support/callbacks.rb:118:in `block in run_callbacks'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/actiontext-7.0.2.2/lib/action_text/rendering.rb:20:in `with_renderer'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/actiontext-7.0.2.2/lib/action_text/engine.rb:69:in `block (4 levels) in <class:Engine>'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activesupport-7.0.2.2/lib/active_support/callbacks.rb:127:in `instance_exec'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activesupport-7.0.2.2/lib/active_support/callbacks.rb:127:in `block in run_callbacks'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activesupport-7.0.2.2/lib/active_support/callbacks.rb:138:in `run_callbacks'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/actionpack-7.0.2.2/lib/abstract_controller/callbacks.rb:233:in `process_action'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/actionpack-7.0.2.2/lib/action_controller/metal/rescue.rb:22:in `process_action'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/actionpack-7.0.2.2/lib/action_controller/metal/instrumentation.rb:67:in `block in process_action'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activesupport-7.0.2.2/lib/active_support/notifications.rb:206:in `block in instrument'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activesupport-7.0.2.2/lib/active_support/notifications/instrumenter.rb:24:in `instrument'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activesupport-7.0.2.2/lib/active_support/notifications.rb:206:in `instrument'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/actionpack-7.0.2.2/lib/action_controller/metal/instrumentation.rb:66:in `process_action'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/actionpack-7.0.2.2/lib/action_controller/metal/params_wrapper.rb:259:in `process_action'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activerecord-7.0.2.2/lib/active_record/railties/controller_runtime.rb:27:in `process_action'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/actionpack-7.0.2.2/lib/abstract_controller/base.rb:151:in `process'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/actionview-7.0.2.2/lib/action_view/rendering.rb:39:in `process'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/actionpack-7.0.2.2/lib/action_controller/metal/live.rb:266:in `block (2 levels) in process'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activesupport-7.0.2.2/lib/active_support/concurrency/share_lock.rb:162:in `sharing'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/activesupport-7.0.2.2/lib/active_support/dependencies/interlock.rb:37:in `running'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/actionpack-7.0.2.2/lib/action_controller/metal/live.rb:258:in `block in process'
rails7-on-docker-web-1    |     from /usr/local/bundle/gems/actionpack-7.0.2.2/lib/action_controller/metal/live.rb:343:in `block in new_controller_thread'
rails7-on-docker-web-1 exited with code 1

When I run the app natively directly without docker I get another error:

` `require': dlopen(/Users/heron/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/ffi-1.15.5/lib/ffi_c.bundle, 9): no suitable image found.  Did find: (LoadError)
        /Users/heron/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/ffi-1.15.5/lib/ffi_c.bundle: mach-o, but wrong architecture

I do not know if this is a rails 7 problem or has to do with my machine even. I am using an M1 Mac machine !


Solution

  • From this Github thread

    Assign the variant processor in your application.rb to :mini_magic or any other processor that you have on your machine.

    for me config.active_storage.variant_processor = :mini_magick solved the crashing problem.