Daniel Bonnell
Daniel Bonnell

Reputation: 4997

Validation failed: Video Paperclip::Errors::NotIdentifiedByImageMagickError

I have a model with an attached video. I want to create a scaled version of the video along with a series of thumbnails. I have the following setup:

has_attached_file :video,
    styles: {
        original: { format: 'mp4', processors: [:transcoder] },
        large: { geometry: "720x720", format: 'jpg', processors: [:thumbnail] },
        medium: { geometry: "540x540", format: 'jpg', processors: [:thumbnail] },
        thumb: { geometry: "180x180", format: 'jpg', processors: [:thumbnail] }
    },
    default_url: ""

When I test this in my development environment it works perfectly. The video and all images are correctly sized. When I deploy to Heroku however, I get the following error:

Validation failed: Video Paperclip::Errors::NotIdentifiedByImageMagickError
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.2/lib/active_record/validations.rb:78:in `raise_validation_error'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.2/lib/active_record/validations.rb:50:in `save!'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.2/lib/active_record/attribute_methods/dirty.rb:30:in `save!'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.2/lib/active_record/transactions.rb:324:in `block in save!'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.2/lib/active_record/transactions.rb:395:in `block in with_transaction_returning_status'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `block in transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.2/lib/active_record/connection_adapters/abstract/transaction.rb:189:in `within_new_transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.2/lib/active_record/transactions.rb:211:in `transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.2/lib/active_record/transactions.rb:392:in `with_transaction_returning_status'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.2/lib/active_record/transactions.rb:324:in `save!'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.2/lib/active_record/suppressor.rb:45:in `save!'
/app/app/models/concerns/snapshot_methods.rb:37:in `copy_from_ziggeo!'
/app/app/workers/snapshot_transcoder.rb:16:in `perform'
/app/vendor/bundle/ruby/2.3.0/gems/resque-status-0.5.0/lib/resque/plugins/status.rb:161:in `safe_perform!'
/app/vendor/bundle/ruby/2.3.0/gems/resque-status-0.5.0/lib/resque/plugins/status.rb:137:in `perform'

What am I missing here? I've searched for NotIdentifiedByImageMagickError and scanned numerous other questions on this issue, but have not had any success fixing my problem.

Most of the solutions I've seen involve setting Paperclip.options[:command_path] = "/usr/bin/identify" in development. Since my problem is only on production, I tried applying this to production, subbing in the correct path for my production environment, like so:

Paperclip.options[:command_path] = "/app/vender/imagemagick/bin/identify"

This had no effect. Neither did /app/vender/imagemagick/bin.

Upvotes: 0

Views: 342

Answers (1)

Daniel Bonnell
Daniel Bonnell

Reputation: 4997

After much head-banging I managed to solve this by purging my app's cache and re-installing ImageMagick. Here are the steps I took:

  1. Install the heroku-repo CLI and run heroku repo:purge_cache -a APP_NAME.
  2. Create an empty commit: git commit --allow-empty -m "Hope this works"
  3. Redeploy to Heroku: git push heroku master

Redeploying takes several minutes since Heroku now has to rebuild all your static assets and dependencies from scratch.

From what I understand, this problem is somehow caused by a faulty cached copy of ImageMagick. I'll happily accept the answer of anyone who can provide a more informed explanation for what caused this issue. Even though it's solved for now, I'm not convinced that this won't just happen again at some random point in the future.

Upvotes: 0

Related Questions