carrierwaveuploader / carrierwave

Classier solution for file uploads for Rails, Sinatra and other Ruby web frameworks
https://github.com/carrierwaveuploader/carrierwave
8.78k stars 1.66k forks source link

recreate_versions! giving error: undefined method `body' for nil:NilClass #1931

Closed snoblenet closed 5 years ago

snoblenet commented 8 years ago

I am storing images on S3.

I am uploading the images to the directory etc that CarrierWave expects using a client-side desktop application, not Rails.

This works. After calling area.update_column :screenshot, "file.png" within Rails, I can get the correct URL using area.screenshot.url.

The images are uploaded as ACL: public-read.

My client-side desktop app only uploads the default version of the image. I then need Rails to create a blurry version.

So, I call area.screenshot.recreate_versions!(:blurry), but this gives me this error:

NoMethodError: undefined method `body' for nil:NilClass
from /Users/steven/.rvm/gems/ruby-2.2.2/gems/carrierwave-0.10.0/lib/carrierwave/storage/fog.rb:228:in `read'

Thoughts?

Relevant lines from my Gemfile.lock:

    carrierwave (0.10.0)
      activemodel (>= 3.2.0)
      activesupport (>= 3.2.0)
      json (>= 1.7)
      mime-types (>= 1.16)
    carrierwave-base64 (2.1.1)
      carrierwave (>= 0.8.0, < 0.11.0)
    carrierwave-imageoptimizer (1.2.1)
      carrierwave (~> 0.8)
      image_optimizer (~> 1.2)
    carrierwave_backgrounder (0.4.2)
      carrierwave (~> 0.5)
    fog (1.37.0)
      fog-aliyun (>= 0.1.0)
      fog-atmos
      fog-aws (>= 0.6.0)
      fog-brightbox (~> 0.4)
      fog-core (~> 1.32)
      fog-dynect (~> 0.0.2)
      fog-ecloud (~> 0.1)
      fog-google (<= 0.1.0)
      fog-json
      fog-local
      fog-powerdns (>= 0.1.1)
      fog-profitbricks
      fog-radosgw (>= 0.0.2)
      fog-riakcs
      fog-sakuracloud (>= 0.0.4)
      fog-serverlove
      fog-softlayer
      fog-storm_on_demand
      fog-terremark
      fog-vmfusion
      fog-voxel
      fog-vsphere (>= 0.4.0)
      fog-xenserver
      fog-xml (~> 0.1.1)
      ipaddress (~> 0.5)
    fog-aliyun (0.1.0)
      fog-core (~> 1.27)
      fog-json (~> 1.0)
      ipaddress (~> 0.8)
      xml-simple (~> 1.1)
    fog-atmos (0.1.0)
      fog-core
      fog-xml
    fog-aws (0.8.1)
      fog-core (~> 1.27)
      fog-json (~> 1.0)
      fog-xml (~> 0.1)
      ipaddress (~> 0.8)
    fog-brightbox (0.10.1)
      fog-core (~> 1.22)
      fog-json
      inflecto (~> 0.0.2)
    fog-core (1.35.0)
      builder
      excon (~> 0.45)
      formatador (~> 0.2)
    fog-dynect (0.0.2)
      fog-core
      fog-json
      fog-xml
    fog-ecloud (0.3.0)
      fog-core
      fog-xml
    fog-google (0.1.0)
      fog-core
      fog-json
      fog-xml
    fog-json (1.0.2)
      fog-core (~> 1.0)
      multi_json (~> 1.10)
    fog-local (0.2.1)
      fog-core (~> 1.27)
    fog-powerdns (0.1.1)
      fog-core (~> 1.27)
      fog-json (~> 1.0)
      fog-xml (~> 0.1)
    fog-profitbricks (0.0.5)
      fog-core
      fog-xml
      nokogiri
    fog-radosgw (0.0.5)
      fog-core (>= 1.21.0)
      fog-json
      fog-xml (>= 0.0.1)
    fog-riakcs (0.1.0)
      fog-core
      fog-json
      fog-xml
    fog-sakuracloud (1.7.5)
      fog-core
      fog-json
    fog-serverlove (0.1.2)
      fog-core
      fog-json
    fog-softlayer (1.0.3)
      fog-core
      fog-json
    fog-storm_on_demand (0.1.1)
      fog-core
      fog-json
    fog-terremark (0.1.0)
      fog-core
      fog-xml
    fog-vmfusion (0.1.0)
      fission
      fog-core
    fog-voxel (0.1.0)
      fog-core
      fog-xml
    fog-vsphere (0.5.0)
      fog-core
      rbvmomi (~> 1.8)
    fog-xenserver (0.2.3)
      fog-core
      fog-xml
    fog-xml (0.1.2)
      fog-core
      nokogiri (~> 1.5, >= 1.5.11)
snoblenet commented 8 years ago

Update, I am trying to address this the long way around with:

area.remote_screenshot_url = area.screenshot.url
area.save!

But I am getting:

ActiveRecord::RecordInvalid: Validation failed: Screenshot Failed to manipulate with MiniMagick, maybe it is not an image? Original Error: `mogrify -blur-image 0 8 /var/folders/k9/vnpft_6d7qs6xmdb9_4svvmw0000gn/T/mini_magick20160503-8871-1jddvc6.png` failed with error:
mogrify: unrecognized option `-blur-image' @ error/mogrify.c/MogrifyImageCommand/4175.
from /Users/steven/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.5/lib/active_record/validations.rb:79:in `raise_record_invalid'

I have downloaded the image manually from S3 and opened it to check it is an image. The blur option works fine aside from in this situation. It reads:

  version :blurry do
    process :blur => [0, 8]
  end

  def blur(radius, sigma)
    manipulate! do |img|
      img = img.blur_image(radius, sigma)
      img = yield(img) if block_given?
      img
    end
  end
bdandy commented 8 years ago

Bug still present in carrierwave 0.11.2:

NoMethodError: undefined method `body' for nil:NilClass
        from /home/ubuntu/apps/celluloidheaven/shared/bundle/ruby/2.1.0/gems/carrierwave-0.11.2/lib/carrierwave/storage/fog.rb:226:in `read'
        from /home/ubuntu/apps/celluloidheaven/shared/bundle/ruby/2.1.0/gems/carrierwave-0.11.2/lib/carrierwave/uploader/cache.rb:89:in `sanitized_file'
        from /home/ubuntu/apps/celluloidheaven/shared/bundle/ruby/2.1.0/gems/carrierwave-0.11.2/lib/carrierwave/uploader/cache.rb:128:in `cache!'
        from (irb):61:in `block in irb_binding'
        from (irb):61:in `each'
        from (irb):61
        from /home/ubuntu/apps/celluloidheaven/shared/bundle/ruby/2.1.0/gems/railties-4.1.1/lib/rails/commands/console.rb:90:in `start'
        from /home/ubuntu/apps/celluloidheaven/shared/bundle/ruby/2.1.0/gems/railties-4.1.1/lib/rails/commands/console.rb:9:in `start'
        from /home/ubuntu/apps/celluloidheaven/shared/bundle/ruby/2.1.0/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:69:in `console'
        from /home/ubuntu/apps/celluloidheaven/shared/bundle/ruby/2.1.0/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
        from /home/ubuntu/apps/celluloidheaven/shared/bundle/ruby/2.1.0/gems/railties-4.1.1/lib/rails/commands.rb:17:in `<top (required)>'
        from bin/rails:4:in `require'
        from bin/rails:4:in `<main>'
ErvalhouS commented 7 years ago

This error occours here, but versions are created on S3 nevertheless.

davidwparker commented 7 years ago

Related, I believe: https://github.com/carrierwaveuploader/carrierwave/issues/828

yunixon commented 6 years ago

Sometimes we get this error:

A NoMethodError occurred in background at 2018-04-16 10:36:19 -0400 :

undefined method `body' for nil:NilClass
/home/deployer/apps/tfl/shared/bundle/ruby/2.4.0/gems/carrierwave-1.2.1/lib/carrierwave/storage/fog.rb:279:in `read'
-------------------------------
Backtrace:
/home/deployer/apps/tfl/shared/bundle/ruby/2.4.0/gems/carrierwave-1.2.1/lib/carrierwave/storage/fog.rb:279:in `read'
/home/deployer/apps/tfl/shared/bundle/ruby/2.4.0/gems/activesupport-5.0.6/lib/active_support/core_ext/object/try.rb:17:in `public_send'
/home/deployer/apps/tfl/shared/bundle/ruby/2.4.0/gems/activesupport-5.0.6/lib/active_support/core_ext/object/try.rb:17:in `try!'
/home/deployer/apps/tfl/shared/bundle/ruby/2.4.0/gems/activesupport-5.0.6/lib/active_support/core_ext/object/try.rb:6:in `try'
/home/deployer/apps/tfl/shared/bundle/ruby/2.4.0/gems/carrierwave-1.2.1/lib/carrierwave/uploader/proxy.rb:44:in `read'
cdesch commented 5 years ago

This seems to be still happening.

mshibuya commented 5 years ago

1879 should have fixed this.

antonakospanos commented 5 years ago

When are we going to have this released?

coding-bunny commented 5 years ago

Any update on this? Running in the exact same problem on our Sidekiq + CarrierWave and really need this working. Works fine in a console, but not over a Sidekiq Job

eric-khoury commented 2 years ago

Any solution for this yet?

robins35 commented 2 years ago

This issue is 6 years old, why is there no fix yet?

mshibuya commented 2 years ago

The fix was already released long ago, as 2.0.0. Open another issue if you still have this.