Imagemagick no such file or directory error in Mac

2019-09-02 17:38发布

I'm using carrierwave to upload images from my rails app, and later pass that image to resque for resizing them in the background. The image gets uploaded properly. The problem when resque tries to resize it, mini_magick says that "No such file or directory"

This is my ImageController code which handles the upload

#create image and embed into story
def create
    img_attr =  params[:image]
    img_attr[:media] = params[:image][:media].first if params[:image][:media].class == Array

    image = Image.new img_attr
    @story.images << image
    if @story.save
        Resque.enqueue(ImageQueue,image.id)
        respond_to do |format|
            format.json {
                render :json => [image.to_jq_upload].to_json
            }
        end
    else
        render :json => [{:error => 'custom_failure'}], :status => 304
    end

end

And this is my Resque code

class ImageQueue
@queue = :image_queue
def self.perform(image_id)
    image = Image.find image_id
    image.recreate_delayed_versions!
    image.save
end
end

And the upload path is set here

def store_dir
    "uploads/stories/#{model.viewable_id}/res"
end

This is the error stack that I get

No such file or directory - /uploads/stories/533d5b8756617390c0070000/res/636a8fe128.jpg
/Users/skmvasu/.rvm/gems/ruby-2.0.0-p451/gems/mini_magick-3.7.0/lib/mini_magick/image.rb:110:in `initialize'
/Users/skmvasu/.rvm/gems/ruby-2.0.0-p451/gems/mini_magick-3.7.0/lib/mini_magick/image.rb:110:in `open'
/Users/skmvasu/.rvm/gems/ruby-2.0.0-p451/gems/mini_magick-3.7.0/lib/mini_magick/image.rb:110:in `open'
/Users/skmvasu/repo/mangoweb/app/uploaders/image_uploader.rb:97:in `original_dimensions'
/Users/skmvasu/.rvm/gems/ruby-2.0.0-p451/gems/carrierwave-0.10.0/lib/carrierwave/uploader/processing.rb:84:in `block in process!'
/Users/skmvasu/.rvm/gems/ruby-2.0.0-p451/gems/carrierwave-0.10.0/lib/carrierwave/uploader/processing.rb:76:in `each'
/Users/skmvasu/.rvm/gems/ruby-2.0.0-p451/gems/carrierwave-0.10.0/lib/carrierwave/uploader/processing.rb:76:in `process!'

The weird thing is the same code works in my Linux box, and my production box which also runs Linux, but not on my new Mac. Is it a problem with ImageMagick? I'm installing it through Homebrew. I even tried uninstalling it and reinstalling it with source, but that didn't work either.

I'm not sure what I'm doing wrong here? Please help me solve this issue.

1条回答
做自己的国王
2楼-- · 2019-09-02 18:19

As per the error,

No such file or directory - /uploads/stories/533d5b8756617390c0070000/res/636a8fe128.jpg

Either 636a8fe128.jpg is not there at the given path i.e., /uploads/stories/533d5b8756617390c0070000/res or

/uploads/stories/533d5b8756617390c0070000/res one or all of the directories in this path are not there. I would recommend go to terminal and navigate through the path and see if it allows you to change directory till you reach res directory. If yes, then inside res directory do ls -l and see if the output shows 636a8fe128.jpg file.

UPDATE

Specify the full path including Rails.root:

def store_dir 
  "#{Rails.root}/public/uploads/stories/#{model.viewable_id}/res" 
end

without #{Rails.root}/public/, path generated was /uploads/stories/533d5b8756617390c0070000/res/636a8fe128.jpg where the first / points to the root directory of the server.

查看更多
登录 后发表回答