1

I'm trying to use this solution to get the dimensions of an image. In development works great, but in staging (using fog) with img = ::Magick::Image::read(@file.file).first throws me: private method 'file' called for #<CarrierWave::Storage::Fog::File:0x00000008fe28d0>

How can I retrieve the file with fog?

Update:

I'm using carrirwave_backgrounder to process the images asynchronously. This is part of the code:

# the uploader
def geometry
  @geometry ||= get_geometry
end

def get_geometry
  if(@file)
    img = ::MiniMagick::Image.open(@file.file)
    @geometry = {width: img[:width], height: img[:height]}
  end
end

# the model
mount_uploader :image, ImageUploader
process_in_background :image
before_save :set_dimensions


def set_dimensions
  geometry = self.image.geometry
  self.width = geometry[:width]
  self.height = geometry[:height]
end

I've figured out that the error appears just when I update the model, not when this is created, so I've changed the callback to before_create :set_dimensions and works fine. I suppose it could be because when I'm updating, the file is just in the assets host, but is just a guessing.

Community
  • 1
  • 1
Alter Lagos
  • 12,090
  • 1
  • 70
  • 92
  • Weird work out of box for me everytime Can u paste uploader code – Viren May 09 '13 at 06:45
  • @Viren I've solved the issue in some way, but anyways check the updated question. Thanks – Alter Lagos May 09 '13 at 15:58
  • If it was `after_save` it will not work because preprocessing hapeen `before` save because in `after_save` u you would `@file` instance as `fog` instead of `CarrierWave:SantizedFile` – Viren May 10 '13 at 05:09
  • @Viren I never said that I used `after_save`. At first I used `before_save` and after that I changed to `before_create`. The error happened just when I updated to record, not to create it. – Alter Lagos May 10 '13 at 14:10

1 Answers1

0

Change file for url, so it will be:

img = ::MiniMagick::Image.open(@file.url)
MaicolBen
  • 840
  • 1
  • 6
  • 20