Search code examples
rubyimagemagicksinatrarmagickpadrino

RMagick - S3 - Heroku, problems with RMagick file open


I am trying to upload a file from browser, then make one thumbnail from it, then upload both to s3.

 File.open(params[:file][:tempfile]) do |p|
      AWS::S3::Base.establish_connection!(
          :access_key_id     => settings.s3_key,
          :secret_access_key => settings.s3_secret)
      AWS::S3::S3Object.store(pic_name,p,settings.bucket,:access => :public_read)

      thumb = Magick::Image.read(p)
      thumb.crop_resized!(75, 75, Magick::NorthGravity)

      AWS::S3::Base.establish_connection!(
          :access_key_id     => settings.s3_key,
          :secret_access_key => settings.s3_secret)
      AWS::S3::S3Object.store(pic_name + "s",thumb,settings.bucket,:access => :public_read)

I have tried most of the possible code combinations to make it work, but it gives me a segmentation error

c:0060 p:---- s:0261 b:0261 l:000260 d:000260 CFUNC  :read
c:0059 p:0117 s:0257 b:0257 l:002638 d:000256 BLOCK  /Users/gkay/Documents/yirmiyedi/web/banne/app/controllers/firsat.rb:33
c:0058 p:---- s:0253 b:0253 l:000252 d:000252 FINISH
c:0057 p:---- s:0251 b:0251 l:000250 d:000250 CFUNC  :open
c:0056 p:0190 s:0247 b:0247 l:002638 d:000246 LAMBDA /Users/gkay/Documents/yirmiyedi/web/banne/app/controllers/firsat.rb:27

So it starts when RMagic tries to open the file. I have tried many stuff like

thumb = Magick::Image.read(p).first or [0] etc but none of them worked.

Any ideas? params[:file] is the post param which keeps the file


Solution

  • I'd suggest using Mini Magick instead - it uses a lot less memory and it's much less buggy. We've had a lot of problems with RMagick, but none with mini magick. And switching from one to the other is very easy.